Multiple
Hard
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
Write a program to determine the smallest positive integer K that is made up solely of the given digits and is divisible by the specified integer N.
Input
The first line of the input contains an integer N (1 < N < 5000). The second line provides between 1 and 10 distinct digits from which the number K should be constructed.
Output
On the first line of the output, print the integer K if it exists, or 0 if no such number can be formed.
Examples
Input #1
Answer #1
Submissions 493
Acceptance rate 6%