#P1602. sramoc Phone Number

    ID: 14888 Type: Default 1000ms 256MiB

sramoc Phone Number

sramoc Phone Number

Given two integers k and m, find the smallest positive integer that is divisible by m and whose decimal representation consists only of the digits from 0 to k-1. This number is denoted as \(sramoc(k,m)\). For example, when k = 2 and m = 7, we have \(sramoc(2,7)=1001\).

Note that the number must not have leading zeros. Use breadth-first search (BFS) or any equivalent strategy to efficiently search for the answer.

inputFormat

The input consists of a single line containing two integers k and m separated by a space.

outputFormat

Output the smallest positive integer that is divisible by m and is composed solely of digits from 0 to k-1.

sample

2 7
1001