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

dp[0] = 0
for i in range(1, n + 1):
    for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1)

num = []
k = n
for i in range(dp[n]):
    for j in a:
        if k >= match[j - 1]:
            if dp[k - match[j - 1]] == dp[k] - 1:
                num.append(j)
                k -= match[j - 1]
                break
print("".join(map(str, num))) 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 match = [2, 5, 5, 4, 5, 6, 3, 7, 6] match [2, 5, 5, 4, 5, 6, 3, 7, 6] 2 5 5 4 5 6 3 7 6 dp = [-1] * (n + 1) dp [-1] * (n + 1) [-1] -1 n + 1 n 1 dp[0] = 0 dp[0] dp 0 0 for i in range(1, n + 1):
    for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1) i range(1, n + 1) range 1 n + 1 n 1 for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1) j a if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1) i < match[j - 1] i match[j - 1] match j - 1 j 1 continue dp[i] = max(dp[i], dp[i - match[j - 1]] + 1) dp[i] dp i max(dp[i], dp[i - match[j - 1]] + 1) max dp[i] dp i dp[i - match[j - 1]] + 1 dp[i - match[j - 1]] dp i - match[j - 1] i match[j - 1] match j - 1 j 1 1 num = [] num [] k = n k n for i in range(dp[n]):
    for j in a:
        if k >= match[j - 1]:
            if dp[k - match[j - 1]] == dp[k] - 1:
                num.append(j)
                k -= match[j - 1]
                break i range(dp[n]) range dp[n] dp n for j in a:
        if k >= match[j - 1]:
            if dp[k - match[j - 1]] == dp[k] - 1:
                num.append(j)
                k -= match[j - 1]
                break j a if k >= match[j - 1]:
            if dp[k - match[j - 1]] == dp[k] - 1:
                num.append(j)
                k -= match[j - 1]
                break k >= match[j - 1] k match[j - 1] match j - 1 j 1 if dp[k - match[j - 1]] == dp[k] - 1:
                num.append(j)
                k -= match[j - 1]
                break dp[k - match[j - 1]] == dp[k] - 1 dp[k - match[j - 1]] dp k - match[j - 1] k match[j - 1] match j - 1 j 1 dp[k] - 1 dp[k] dp k 1 num.append(j) num.append num append j k -= match[j - 1] k match[j - 1] match j - 1 j 1 break print("".join(map(str, num))) print "".join(map(str, num)) "".join "" join map(str, num) map str num m = map(int, input().split()) map(int, input().split()) m num = [] [] num n, m = map(int, input().split()) map(int, input().split()) n dp = [-1] * (n + 1) [-1] * (n + 1) dp k -= match[j - 1] match[j - 1] k match = [2, 5, 5, 4, 5, 6, 3, 7, 6] [2, 5, 5, 4, 5, 6, 3, 7, 6] match k = n n k a = list(map(int, input().split())) list(map(int, input().split())) a
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 1)

dp[0] = 0
for i in range(1, n + 1):
    for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1)

num = []
k = n
for i in range(dp[n]):
    for j in a:
        if k >= match[j - 1]:
            if dp[k - match[j - 1]] == dp[k] - 1:
                num.append(j)
                k -= match[j - 1]
                break
print("".join(map(str, num)))