Matches
You have a set of digits ranging from 0 to k, and you can use a specified number of matches to arrange them on a table. Your goal is to create the largest possible number using exactly n matches. For instance, if the digit 0 requires 6 matches, 1 requires 7 matches, and 2 requires 8 matches, then with 21 matches, the largest number you can form is 210.
Input
The first line contains two integers, n and k (1 ≤ n ≤ 50, 0 ≤ k ≤ 9). The second line lists k+1 integers, each ranging from 1 to 50, representing the number of matches required for each digit from 0 to k. It is guaranteed that at least one digit can be formed with n matches.
Output
Print the largest number that can be constructed. The output should not contain leading zeros. You are allowed to use fewer than n matches if necessary.