N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = {0: 0}
for i in range(1, N + 1):
    dp[i] = -float('inf')
    for j in range(8, -1, -1):
        if j + 1 in A and i - num[j] >= 0:
            dp[i] = max(dp[i], dp[i - num[j]] + 1)

ans = []
while N > 0:
    for j in range(8, -1, -1):
        if j + 1 in A and N - num[j] in dp and dp[N - num[j]] == dp[N] - 1:
            ans.append(j + 1)
            N -= num[j]
            break

print(*ans, sep='') N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split num = [2, 5, 5, 4, 5, 6, 3, 7, 6] num [2, 5, 5, 4, 5, 6, 3, 7, 6] 2 5 5 4 5 6 3 7 6 dp = {0: 0} dp {0: 0} 0 0 0 for i in range(1, N + 1):
    dp[i] = -float('inf')
    for j in range(8, -1, -1):
        if j + 1 in A and i - num[j] >= 0:
            dp[i] = max(dp[i], dp[i - num[j]] + 1) i range(1, N + 1) range 1 N + 1 N 1 dp[i] = -float('inf') dp[i] dp i -float('inf') float('inf') float 'inf' for j in range(8, -1, -1):
        if j + 1 in A and i - num[j] >= 0:
            dp[i] = max(dp[i], dp[i - num[j]] + 1) j range(8, -1, -1) range 8 -1 -1 if j + 1 in A and i - num[j] >= 0:
            dp[i] = max(dp[i], dp[i - num[j]] + 1) j + 1 in A and i - num[j] >= 0 j + 1 in A j + 1 j 1 A i - num[j] >= 0 i - num[j] i num[j] num j 0 dp[i] = max(dp[i], dp[i - num[j]] + 1) dp[i] dp i max(dp[i], dp[i - num[j]] + 1) max dp[i] dp i dp[i - num[j]] + 1 dp[i - num[j]] dp i - num[j] i num[j] num j 1 ans = [] ans [] while N > 0:
    for j in range(8, -1, -1):
        if j + 1 in A and N - num[j] in dp and dp[N - num[j]] == dp[N] - 1:
            ans.append(j + 1)
            N -= num[j]
            break N > 0 N 0 for j in range(8, -1, -1):
        if j + 1 in A and N - num[j] in dp and dp[N - num[j]] == dp[N] - 1:
            ans.append(j + 1)
            N -= num[j]
            break j range(8, -1, -1) range 8 -1 -1 if j + 1 in A and N - num[j] in dp and dp[N - num[j]] == dp[N] - 1:
            ans.append(j + 1)
            N -= num[j]
            break j + 1 in A and N - num[j] in dp and dp[N - num[j]] == dp[N] - 1 j + 1 in A and N - num[j] in dp j + 1 in A j + 1 j 1 A N - num[j] in dp N - num[j] N num[j] num j dp dp[N - num[j]] == dp[N] - 1 dp[N - num[j]] dp N - num[j] N num[j] num j dp[N] - 1 dp[N] dp N 1 ans.append(j + 1) ans.append ans append j + 1 j 1 N -= num[j] N num[j] num j break print(*ans, sep='') print *ans ans sep='' sep '' num = [2, 5, 5, 4, 5, 6, 3, 7, 6] [2, 5, 5, 4, 5, 6, 3, 7, 6] num A = list(map(int, input().split())) list(map(int, input().split())) A dp = {0: 0} {0: 0} dp M = map(int, input().split()) map(int, input().split()) M N -= num[j] num[j] N ans = [] [] ans N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = {0: 0}
for i in range(1, N + 1):
    dp[i] = -float('inf')
    for j in range(8, -1, -1):
        if j + 1 in A and i - num[j] >= 0:
            dp[i] = max(dp[i], dp[i - num[j]] + 1)

ans = []
while N > 0:
    for j in range(8, -1, -1):
        if j + 1 in A and N - num[j] in dp and dp[N - num[j]] == dp[N] - 1:
            ans.append(j + 1)
            N -= num[j]
            break

print(*ans, sep='')