N, K = input().split() N = int(N) K = list(int(x) for x in K) C = list(map(int, input().split())) ans = [] if len(K) < N: for i, c in enumerate(C, 1): ans.extend([i] * c) elif len(K) > N: print(-1) exit() else: assert len(K) == N # 不可能 tmp = [] for i, c in enumerate(C, 1): tmp.extend([i] * c) tmp = reversed(tmp) for k, i in zip(K, tmp): if k < i: break elif k > i: print(-1) exit() else: print(-1) flag = False for k in K: if flag: break if C[k - 1]: C[k - 1] -= 1 ans.append(k) continue for j in range(k + 1, 10): if C[j - 1]: C[j - 1] -= 1 ans.append(j) for i, c in enumerate(C, 1): ans.extend([i] * c) flag = True break # 同じになってしまった時の処理 if ans == K: m = 0 for i in range(N - 1, -1, -1): C[ans[i] - 1] += 1 if m > ans[i]: tmp = ans[i] break m = ans[i] ans.pop() for j in range(tmp + 1, 10): if C[j - 1]: C[j - 1] -= 1 ans[i] = j for i, c in enumerate(C, 1): ans.extend([i] * c) break print(''.join(map(str, ans)))