{"raw_statement":[{"iden":"statement","content":"Polycarp have free time, collection of N decimal digits c1, ... , cN and positive integer A. He wants to find positive integer B, such that A divides B and B contains only digits from collection c1, ... , cN. Each digit from collection can be used any times. It is not required to use all the digits.\n\nThe first line contains N — the number of digits in collection, 1 ≤ N ≤ 10. The second line contains N integer numbers ci (0 ≤ ci ≤ 9). Each digit can be there at most one time. The third line contains integer A, 1 ≤ A ≤ 105. \n\nOutput B. If you cannot find it, then output _-1_.\n\n"},{"iden":"input","content":"The first line contains N — the number of digits in collection, 1 ≤ N ≤ 10. The second line contains N integer numbers ci (0 ≤ ci ≤ 9). Each digit can be there at most one time. The third line contains integer A, 1 ≤ A ≤ 105. "},{"iden":"output","content":"Output B. If you cannot find it, then output _-1_."},{"iden":"examples","content":"Input33 5 7123Output5535Input111230Output-1"}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $, $ 1 \\leq N \\leq 10 $, be the number of available digits.  \nLet $ D = \\{c_1, c_2, \\dots, c_N\\} \\subseteq \\{0,1,\\dots,9\\} $ be the set of available digits.  \nLet $ A \\in \\mathbb{Z}^+ $, $ 1 \\leq A \\leq 10^5 $, be the given divisor.  \n\n**Constraints**  \n- All $ c_i \\in D $ are distinct.  \n- $ B \\in \\mathbb{Z}^+ $ must satisfy:  \n  1. $ A \\mid B $,  \n  2. Every digit of $ B $ (in decimal representation) belongs to $ D $.  \n\n**Objective**  \nFind the smallest such $ B $, or output $-1$ if no such $ B $ exists.","simple_statement":"Given a set of allowed digits and a number A, find the smallest positive number B that is divisible by A and uses only the allowed digits. If no such number exists, return -1.","has_page_source":false}