George the monkey was hanging off his favourite branch while watching his favourite anime, when all of a sudden, a potato fell from the sky! Upon examining the potato, he notices
George wants you to use some non-empty combination of digits from the potato to form a positive integer of length
In addition, George doesn't like processing large integers, so he'll only accept the smallest possible answer. If it is impossible to satisfy this task, you'll have to tell him, and he will become a very sad monkey.
Constraints
All
Subtask 1 [20%]
Subtask 2 [80%]
No additional constraints.
Input Specification
The first line of input will contain
The next line will contain
Output Specification
Output the minimum positive integer of length -1
if there is no valid answer.
Sample Input 1
5 6
3 1 2 5 4 9
Sample Output 1
11111
Explanation for Sample 1
It can be proven that
Sample Input 2
1 1
1
Sample Output 2
1
Sample Input 3
6 1
0
Sample Output 3
-1
Comments
Don't you just hate it when you're watching anime and a potato falls on your head
Yes, it is very annoying
Could anyone advise me on why my output stops getting AC after Test Case #4 in Batch #2?
A reminder that sharing solutions in the comments is strongly discouraged. Asking for help in DMOJ Discord is preferable.
Also, editorials exist for the purposes of discussing solutions...
Try the case
Thanks.
Please ask for help in the Discord server.
Sorry, I will do that next time.