n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [[-1, -1] for i in range(n+1)]

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

dp[0] = [0, 0]
for i in range(1, n+1):
    for ai in a:
        ci = c[ai]
        if i - ci >= 0 and dp[i-ci][0] != -1:
            if dp[i][0] < dp[i-ci][0] + 1:
                dp[i] = [dp[i-ci][0] + 1, ai]
i = n
ans = []
while i > 0:
    ai = dp[i][1]
    ans.append(ai)
    i -= c[ai]
print("".join(map(str, ans)))
