n,m = map(int, input().split())
l = [2,5,5,4,5,6,3,7,6]

a = list(map(int, input().split()))
a.sort(reverse=True)
key = set([l[i-1] for i in a])

dp = [-float("inf")]*(n+1)
dp[0] = 0
for i in range(n):
    for j in key:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1)

i = n
ans = []
while i > 0:
    for ai in a:
        if i-l[ai-1] >= 0 and dp[i]-dp[i-l[ai-1]] == 1:
            ans.append(ai)
            i -= l[ai-1]
            break
print("".join(map(str, ans))) n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l = [2,5,5,4,5,6,3,7,6] l [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 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 l[i-1] for i in a for i in a i a for i in a l[i-1] l i-1 i 1 key = set([l[i-1] for i in a]) key set([l[i-1] for i in a]) set [l[i-1] for i in a] dp = [-float("inf")]*(n+1) dp [-float("inf")]*(n+1) [-float("inf")] -float("inf") float("inf") float "inf" n+1 n 1 dp[0] = 0 dp[0] dp 0 0 for i in range(n):
    for j in key:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1) i range(n) range n for j in key:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1) j key if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1) i+j <= n i+j i j n dp[i+j] = max(dp[i+j], dp[i]+1) dp[i+j] dp i+j i j max(dp[i+j], dp[i]+1) max dp[i+j] dp i+j i j dp[i]+1 dp[i] dp i 1 i = n i n ans = [] ans [] while i > 0:
    for ai in a:
        if i-l[ai-1] >= 0 and dp[i]-dp[i-l[ai-1]] == 1:
            ans.append(ai)
            i -= l[ai-1]
            break i > 0 i 0 for ai in a:
        if i-l[ai-1] >= 0 and dp[i]-dp[i-l[ai-1]] == 1:
            ans.append(ai)
            i -= l[ai-1]
            break ai a if i-l[ai-1] >= 0 and dp[i]-dp[i-l[ai-1]] == 1:
            ans.append(ai)
            i -= l[ai-1]
            break i-l[ai-1] >= 0 and dp[i]-dp[i-l[ai-1]] == 1 i-l[ai-1] >= 0 i-l[ai-1] i l[ai-1] l ai-1 ai 1 0 dp[i]-dp[i-l[ai-1]] == 1 dp[i]-dp[i-l[ai-1]] dp[i] dp i dp[i-l[ai-1]] dp i-l[ai-1] i l[ai-1] l ai-1 ai 1 1 ans.append(ai) ans.append ans append ai i -= l[ai-1] i l[ai-1] l ai-1 ai 1 break print("".join(map(str, ans))) print "".join(map(str, ans)) "".join "" join map(str, ans) map str ans a = list(map(int, input().split())) list(map(int, input().split())) a i = n n i i -= l[ai-1] l[ai-1] i m = map(int, input().split()) map(int, input().split()) m key = set([l[i-1] for i in a]) set([l[i-1] for i in a]) key n,m = map(int, input().split()) map(int, input().split()) n ans = [] [] ans dp = [-float("inf")]*(n+1) [-float("inf")]*(n+1) dp l = [2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] l
n,m = map(int, input().split())
l = [2,5,5,4,5,6,3,7,6]

a = list(map(int, input().split()))
a.sort(reverse=True)
key = set([l[i-1] for i in a])

dp = [-float("inf")]*(n+1)
dp[0] = 0
for i in range(n):
    for j in key:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1)

i = n
ans = []
while i > 0:
    for ai in a:
        if i-l[ai-1] >= 0 and dp[i]-dp[i-l[ai-1]] == 1:
            ans.append(ai)
            i -= l[ai-1]
            break
print("".join(map(str, ans)))