Large number#447

Large number

3 seconds
64 megabytes
Hard

Given a positive integer and a set of digits , find the smallest positive integer divisible by such that its decimal representation contains only digits from , and no two consecutive digits are the same.

Input

The first line contains the set of allowed digits, listed in ascending order, without spaces or duplicates. The set may be empty.

The second line contains a single integer (1 \leq K \leq 10^5).

Output

Print such a number if it exists. If there is no such number, print –1.

Examples

Example 1

Loading
Loading