n,k = input().split() C = list(map(int,input().split())) n = int(n) def search(x): C2 = C[:] for i in range(x-1): num = int(k[i])-1 C2[num] -= 1 if C2[num] < 0: return False num = int(k[x-1]) for i in range(num,9): if C2[i]: return True return False l = 0 r = n while r > l + 1: m = (r+l)//2 if search(m): l = m else: r = m if l == 0: print(-1) exit() ans = [] for i in range(l-1): ans.append(k[i]) C[int(k[i])-1] -= 1 num = int(k[l-1]) for j in range(num,9): if C[j]: ans.append(j+1) C[j] -= 1 break for i,c in enumerate(C,1): for j in range(c): ans.append(i) print(*ans,sep="")