n, k = map(str, input().split()) n = int(n) C = list(map(int, input().split())) import copy D = copy.copy(C) if n < len(k): print(-1) exit() if n > len(k): ans = [] for i, c in enumerate(C): ans += [str(i+1)]*c print(''.join(ans)) exit() l = len(k) k = list(k) npd, p = -1, -1 for i in range(l): d = int(k[i]) nd = -1 for j in range(d+1, 10): if C[j-1] > 0: nd = j break if nd != -1: p = i npd = nd if d == 0: break if not C[d-1]: break else: C[d-1] -= 1 if p == -1: print(-1) exit() ans = k[0:p]+[str(npd)] for d in k[0:p]: d = int(d) if d != 0: D[d-1] -= 1 D[npd-1] -= 1 for i, c in enumerate(D): ans += [str(i+1)]*c print(''.join(ans))