提示: 欢迎访问OurACM平台。因与高数考试冲突,校赛改为5月6日13:00-17:00
Problem 1028 Multiple

Accept: 102    Submit: 560
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

a program that, given a natural number N between 0 and 4999 (inclusively), and M distinct decimal digits X1,X2..XM (at least one), finds the smallest strictly positive multiple of N that has no other digits besides X1,X2..XM (if such a multiple exists).

The input file has several data sets separated by an empty line, each data set having the following format:

On the first line - the number N
On the second line - the number M
On the following M lines - the digits X1,X2..XM.

For each data set, the program should write to standard output on a single line the multiple, if such a multiple exists, and 0 otherwise.

An example of input and output:


Sample Input

22 3 7 0 1 2 1 1

Sample Output

110 0

Source

Southeastern European Regional Programming Contest 2000 C

Submit  Back  Status  Discuss