N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
INF = float('inf')
dp = [-INF]*(N + 5)
needs = [2, 5, 5, 4, 5, 6, 3, 7, 6]
can_use = {k: needs[k-1] for k in A}
dp[0] = 0
for i in range(2, N+1):
    for v in can_use.values():
        if i - v < 0:
            continue
        dp[i] = max(dp[i], dp[i-v]+1)
ans = ''
i = N
while i != 0:
    for k, v in can_use.items():
        if i - v < 0:
            continue
        while dp[i] == dp[i-v] + 1:
            ans += str(k)
            i -= v
print(ans) 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 A.sort(reverse=True) A.sort A sort reverse=True reverse True INF = float('inf') INF float('inf') float 'inf' dp = [-INF]*(N + 5) dp [-INF]*(N + 5) [-INF] -INF INF N + 5 N 5 needs = [2, 5, 5, 4, 5, 6, 3, 7, 6] needs [2, 5, 5, 4, 5, 6, 3, 7, 6] 2 5 5 4 5 6 3 7 6 k: needs[k-1] for k in A for k in A k A for k in A k needs[k-1] needs k-1 k 1 can_use = {k: needs[k-1] for k in A} can_use {k: needs[k-1] for k in A} dp[0] = 0 dp[0] dp 0 0 for i in range(2, N+1):
    for v in can_use.values():
        if i - v < 0:
            continue
        dp[i] = max(dp[i], dp[i-v]+1) i range(2, N+1) range 2 N+1 N 1 for v in can_use.values():
        if i - v < 0:
            continue
        dp[i] = max(dp[i], dp[i-v]+1) v can_use.values() can_use.values can_use values if i - v < 0:
            continue
         i - v < 0 i - v i v 0 continue dp[i] = max(dp[i], dp[i-v]+1) dp[i] dp i max(dp[i], dp[i-v]+1) max dp[i] dp i dp[i-v]+1 dp[i-v] dp i-v i v 1 ans = '' ans '' i = N i N while i != 0:
    for k, v in can_use.items():
        if i - v < 0:
            continue
        while dp[i] == dp[i-v] + 1:
            ans += str(k)
            i -= v i != 0 i 0 for k, v in can_use.items():
        if i - v < 0:
            continue
        while dp[i] == dp[i-v] + 1:
            ans += str(k)
            i -= v k v can_use.items() can_use.items can_use items if i - v < 0:
            continue
         i - v < 0 i - v i v 0 continue while dp[i] == dp[i-v] + 1:
            ans += str(k)
            i -= v dp[i] == dp[i-v] + 1 dp[i] dp i dp[i-v] + 1 dp[i-v] dp i-v i v 1 ans += str(k) ans str(k) str k i -= v i v print(ans) print ans i -= v v i INF = float('inf') float('inf') INF M = map(int, input().split()) map(int, input().split()) M dp = [-INF]*(N + 5) [-INF]*(N + 5) dp needs = [2, 5, 5, 4, 5, 6, 3, 7, 6] [2, 5, 5, 4, 5, 6, 3, 7, 6] needs ans = '' '' ans ans += str(k) str(k) ans i = N N i A = list(map(int, input().split())) list(map(int, input().split())) A can_use = {k: needs[k-1] for k in A} {k: needs[k-1] for k in A} can_use N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
INF = float('inf')
dp = [-INF]*(N + 5)
needs = [2, 5, 5, 4, 5, 6, 3, 7, 6]
can_use = {k: needs[k-1] for k in A}
dp[0] = 0
for i in range(2, N+1):
    for v in can_use.values():
        if i - v < 0:
            continue
        dp[i] = max(dp[i], dp[i-v]+1)
ans = ''
i = N
while i != 0:
    for k, v in can_use.items():
        if i - v < 0:
            continue
        while dp[i] == dp[i-v] + 1:
            ans += str(k)
            i -= v
print(ans)
