import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto s = readln.split; auto N = s[0].to!int; auto M = s[1]; auto A = 0 ~ readln.split.map!(to!int).array; auto ans = new int[](N); bool same(int i) { return A[i] > 0; } int larger(int i) { foreach (j; i+1..10) if (A[j] > 0) return j; return -1; } void build_ans(int idx) { foreach (i; idx..N) { foreach (j; 1..10) if (A[j]) { ans[i] = j; A[j] -= 1; break; } } } bool dfs(int i) { if (i == N) { return false; } int n = (M[i] - '0').to!int; if (same(n)) { ans[i] = n; A[n] -= 1; } else if (larger(n) != -1) { int m = larger(n); ans[i] = m; A[m] -= 1; build_ans(i+1); return true; } else { return false; } auto ret = dfs(i+1); if (ret) { return true; } else if (larger(n) != -1) { A[n] += 1; int m = larger(n); ans[i] = m; A[m] -= 1; build_ans(i+1); return true; } else { A[n] += 1; return false; } } auto ret = dfs(0); if (ret) { ans.map!(to!string).join().writeln; } else { writeln(-1); } } long powmod(long a, long x, long m) { long ret = 1; while (x) { if (x % 2) ret = ret * a % m; a = a * a % m; x /= 2; } return ret; }