wavynumbers
Wavy Numbers
A wavy number is a positive integer that for any digit of its decimal representation, the following condition holds: The digit is either strictly larger than all adjacent digits or strictly smaller than all adjacent digits. For example, numbers , , , and are wavy but numbers , , , and are not.
The task is to find the smallest wavy number that is divisible by , for the given integer values and .
You are to write a program that will find the value of if it doesn't exceed .
Input format
The only line of input contains two integers and , separated by a single space.
Output format
Output a single integer — the answer to the given problem. If such a number does not exist or it is larger than , then print "-1" (negative one without the quotes) instead.
Limits
.
Subtask #
|
Score
|
Constraints
|
1 |
11 |
|
2 |
13 |
|
3 |
15 |
|
4 |
61 |
No additional constraints |
Samples
Sample Input 1
|
Sample Output 1
|
123 4
|
1845
|
The values of the first four wavy numbers that are divisible by are: , , and .
Sample Input 2
|
Sample Output 2
|
100 1
|
-1
|
Sample Input 3
|
Sample Output 3
|
97461 457
|
1805270103
|