n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 10)
dp[0] = 0

for i in range(n):
    for ai in a:
        if dp[i] >= 0:
            dp[i + cost[ai]] = dp[i] + 1

ans = []
i = n
while dp[i] > 0:
    for ai in a:
        if dp[i - cost[ai]] == dp[i] - 1:
            ans.append(str(ai))
            i -= cost[ai]
            break

print(''.join(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 cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] cost [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 dp = [-1] * (n + 10) dp [-1] * (n + 10) [-1] -1 n + 10 n 10 dp[0] = 0 dp[0] dp 0 0 for i in range(n):
    for ai in a:
        if dp[i] >= 0:
            dp[i + cost[ai]] = dp[i] + 1 i range(n) range n for ai in a:
        if dp[i] >= 0:
            dp[i + cost[ai]] = dp[i] + 1 ai a if dp[i] >= 0:
            dp[i + cost[ai]] = dp[i] + 1 dp[i] >= 0 dp[i] dp i 0 dp[i + cost[ai]] = dp[i] + 1 dp[i + cost[ai]] dp i + cost[ai] i cost[ai] cost ai dp[i] + 1 dp[i] dp i 1 ans = [] ans [] i = n i n while dp[i] > 0:
    for ai in a:
        if dp[i - cost[ai]] == dp[i] - 1:
            ans.append(str(ai))
            i -= cost[ai]
            break dp[i] > 0 dp[i] dp i 0 for ai in a:
        if dp[i - cost[ai]] == dp[i] - 1:
            ans.append(str(ai))
            i -= cost[ai]
            break ai a if dp[i - cost[ai]] == dp[i] - 1:
            ans.append(str(ai))
            i -= cost[ai]
            break dp[i - cost[ai]] == dp[i] - 1 dp[i - cost[ai]] dp i - cost[ai] i cost[ai] cost ai dp[i] - 1 dp[i] dp i 1 ans.append(str(ai)) ans.append ans append str(ai) str ai i -= cost[ai] i cost[ai] cost ai break print(''.join(ans)) print ''.join(ans) ''.join '' join ans i = n n i i -= cost[ai] cost[ai] i a = list(map(int, input().split())) list(map(int, input().split())) a ans = [] [] ans n, m = map(int, input().split()) map(int, input().split()) n cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] cost dp = [-1] * (n + 10) [-1] * (n + 10) dp m = map(int, input().split()) map(int, input().split()) m
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 10)
dp[0] = 0

for i in range(n):
    for ai in a:
        if dp[i] >= 0:
            dp[i + cost[ai]] = dp[i] + 1

ans = []
i = n
while dp[i] > 0:
    for ai in a:
        if dp[i - cost[ai]] == dp[i] - 1:
            ans.append(str(ai))
            i -= cost[ai]
            break

print(''.join(ans))