Олимпиадный тренинг

Задача 37706. Cards for Misha


Задача

Темы: Множества
Masha invites Misha to play the next game. Masha writes two numbers on a piece of paper, and in front of Misha are cards with numbers from 0 to 9. Misha's task is to choose such cards for himself, on which numbers are written, which are used to write both the first number and the second.

Input: The input is two natural numbers not exceeding 109. Each number on a separate line
Output: Display in ascending order the cards that Misha should take. If Misha cannot take any cards, then print -1

 

Examples
# Input Output
1 514
233
-1
2 1248
3472
2 4