N, M = map(int, input().split())
As = sorted(list(map(int, input().split())), reverse=True)

INF = 10**9
matches = [2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [-INF for _ in range(N+100)]
dp[0] = 0

for i in range(N+1):
    for a in As:
        dp[i+matches[a-1]] = max(dp[i+matches[a-1]], dp[i]+1)

ans = ''
while N != 0:
    for a in As:
        if dp[N-matches[a-1]] == dp[N]-1:
            ans = ans+str(a)
            N -= matches[a-1]
            break

print(ans) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M As = sorted(list(map(int, input().split())), reverse=True) As sorted(list(map(int, input().split())), reverse=True) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split reverse=True reverse True INF = 10**9 INF 10**9 10 9 matches = [2, 5, 5, 4, 5, 6, 3, 7, 6] matches [2, 5, 5, 4, 5, 6, 3, 7, 6] 2 5 5 4 5 6 3 7 6 -INF for _ in range(N+100) for _ in range(N+100) _ range(N+100) range N+100 N 100 for _ in range(N+100) -INF INF dp = [-INF for _ in range(N+100)] dp [-INF for _ in range(N+100)] dp[0] = 0 dp[0] dp 0 0 for i in range(N+1):
    for a in As:
        dp[i+matches[a-1]] = max(dp[i+matches[a-1]], dp[i]+1) i range(N+1) range N+1 N 1 for a in As:
        dp[i+matches[a-1]] = max(dp[i+matches[a-1]], dp[i]+1) a As dp[i+matches[a-1]] = max(dp[i+matches[a-1]], dp[i]+1) dp[i+matches[a-1]] dp i+matches[a-1] i matches[a-1] matches a-1 a 1 max(dp[i+matches[a-1]], dp[i]+1) max dp[i+matches[a-1]] dp i+matches[a-1] i matches[a-1] matches a-1 a 1 dp[i]+1 dp[i] dp i 1 ans = '' ans '' while N != 0:
    for a in As:
        if dp[N-matches[a-1]] == dp[N]-1:
            ans = ans+str(a)
            N -= matches[a-1]
            break N != 0 N 0 for a in As:
        if dp[N-matches[a-1]] == dp[N]-1:
            ans = ans+str(a)
            N -= matches[a-1]
            break a As if dp[N-matches[a-1]] == dp[N]-1:
            ans = ans+str(a)
            N -= matches[a-1]
            break dp[N-matches[a-1]] == dp[N]-1 dp[N-matches[a-1]] dp N-matches[a-1] N matches[a-1] matches a-1 a 1 dp[N]-1 dp[N] dp N 1 ans = ans+str(a) ans ans+str(a) ans str(a) str a N -= matches[a-1] N matches[a-1] matches a-1 a 1 break print(ans) print ans ans = '' '' ans N, M = map(int, input().split()) map(int, input().split()) N matches = [2, 5, 5, 4, 5, 6, 3, 7, 6] [2, 5, 5, 4, 5, 6, 3, 7, 6] matches ans = ans+str(a) ans+str(a) ans N -= matches[a-1] matches[a-1] N INF = 10**9 10**9 INF M = map(int, input().split()) map(int, input().split()) M As = sorted(list(map(int, input().split())), reverse=True) sorted(list(map(int, input().split())), reverse=True) As dp = [-INF for _ in range(N+100)] [-INF for _ in range(N+100)] dp
N, M = map(int, input().split())
As = sorted(list(map(int, input().split())), reverse=True)

INF = 10**9
matches = [2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [-INF for _ in range(N+100)]
dp[0] = 0

for i in range(N+1):
    for a in As:
        dp[i+matches[a-1]] = max(dp[i+matches[a-1]], dp[i]+1)

ans = ''
while N != 0:
    for a in As:
        if dp[N-matches[a-1]] == dp[N]-1:
            ans = ans+str(a)
            N -= matches[a-1]
            break

print(ans)
