N, M = map(int, input().split())
A = map(int, input().split())
ok = [0] * 10
for a in A: ok[a] = 1

dp = [-1] * (N + 1)
dp[0] = 0
cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(N):
    for num in range(1, 10):
        c = cost[num]
        if ok[num] == 0 or i + c > N: continue
        dp[i+c] = max(dp[i+c], dp[i] * 10 + num)

ans = dp[N]
print(ans) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = map(int, input().split()) A map(int, input().split()) map int input().split() ().split () input split ok = [0] * 10 ok [0] * 10 [0] 0 10 for a in A: ok[a] = 1 a A dp = [-1] * (N + 1) dp [-1] * (N + 1) [-1] -1 N + 1 N 1 dp[0] = 0 dp[0] dp 0 0 cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6] cost [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6] -1 2 5 5 4 5 6 3 7 6 for i in range(N):
    for num in range(1, 10):
        c = cost[num]
        if ok[num] == 0 or i + c > N: continue
        dp[i+c] = max(dp[i+c], dp[i] * 10 + num) i range(N) range N for num in range(1, 10):
        c = cost[num]
        if ok[num] == 0 or i + c > N: continue
        dp[i+c] = max(dp[i+c], dp[i] * 10 + num) num range(1, 10) range 1 10 c = cost[num] c cost[num] cost num if ok[num] == 0 or i + c > N: continue
         ok[num] == 0 or i + c > N ok[num] == 0 ok[num] ok num 0 i + c > N i + c i c N dp[i+c] = max(dp[i+c], dp[i] * 10 + num) dp[i+c] dp i+c i c max(dp[i+c], dp[i] * 10 + num) max dp[i+c] dp i+c i c dp[i] * 10 + num dp[i] * 10 dp[i] dp i 10 num ans = dp[N] ans dp[N] dp N print(ans) print ans N, M = map(int, input().split()) map(int, input().split()) N ans = dp[N] dp[N] ans dp = [-1] * (N + 1) [-1] * (N + 1) dp M = map(int, input().split()) map(int, input().split()) M c = cost[num] cost[num] c cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6] [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6] cost A = map(int, input().split()) map(int, input().split()) A ok = [0] * 10 [0] * 10 ok
N, M = map(int, input().split())
A = map(int, input().split())
ok = [0] * 10
for a in A: ok[a] = 1

dp = [-1] * (N + 1)
dp[0] = 0
cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(N):
    for num in range(1, 10):
        c = cost[num]
        if ok[num] == 0 or i + c > N: continue
        dp[i+c] = max(dp[i+c], dp[i] * 10 + num)

ans = dp[N]
print(ans)
