import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 # md = 998244353 md = 10**9+7 def nCr(com_n, com_r): if com_r < 0: return 0 if com_n < com_r: return 0 return fac[com_n]*ifac[com_r]%md*ifac[com_n-com_r]%md # 準備 n_max = 200005 fac = [1] for i in range(1, n_max+1): fac.append(fac[-1]*i%md) ifac = [1]*(n_max+1) ifac[n_max] = pow(fac[n_max], md-2, md) for i in range(n_max-1, 1, -1): ifac[i] = ifac[i+1]*(i+1)%md n, kk = SI().split() n = int(n) cc = LI() kk = list(map(int, kk)) m = len(kk) if n < m: print(-1) exit() if n > m: ans = [] for i, c in enumerate(cc, 1): ans += [i]*c print(*ans, sep="") exit() def ok(k): for i in range(k, 9): if cc[i]-dd[i]: return True return False dd = [0]*9 last = -1 for i, k in enumerate(kk): if k == 0 or ok(k): last = i if cc[k-1] == dd[k-1]: break if k == 0: break dd[k-1] += 1 # print(last) ans = [] for k in kk[:last]: ans.append(k) cc[k-1] -= 1 k = kk[last] for i in range(k, 9): if cc[i]: ans.append(i+1) cc[i] -= 1 break for i in range(9): ans += [i+1]*cc[i] print(*ans, sep="")