N,K = input().split() d = [0] + list(map(int,input().split())) c = d.copy() N = int(N) if len(K) > N: print(-1) exit() for i in range(N-len(K)): K = "0" + K #print(K) a = "" for i0 in range(10): for j in range(c[i0]): a = a + str(i0) ans = [a] s = "" for i in range(N): v = int(K[i]) if c[v]: s = s + str(v) c[v] -= 1 a = s for i0 in range(10): for j in range(c[i0]): a = a + str(i0) ans.append(a) else: break for i in range(int(K[0])+1,10): if d[i]: a = str(i) d[i] -= 1 for i0 in range(10): for j in range(d[i0]): a = a + str(i0) ans.append(a) for v in ans: if K < v: print(v) exit() print(-1)