n,m = map(int,input().split())
A = list(map(int,input().split()))
L = [2,5,5,4,5,6,3,7,6]
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(1,n+1):
    for j in range(m):
        if i-L[A[j]-1] < 0:
            None
        else:
            dp[i] = max(dp[i-L[A[j]-1]]+1, dp[i])
A.sort()
A.reverse()
cur = n
ans = ''
while cur != 0:
    for i in range(m):
        temp = A[i]
        if cur-L[temp-1] >= 0:
            if dp[cur-L[temp-1]] == dp[cur]-1:
                ans = ans+str(temp)
                cur -= L[temp-1]
                break
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 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 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(1,n+1):
    for j in range(m):
        if i-L[A[j]-1] < 0:
            None
        else:
            dp[i] = max(dp[i-L[A[j]-1]]+1, dp[i]) i range(1,n+1) range 1 n+1 n 1 for j in range(m):
        if i-L[A[j]-1] < 0:
            None
        else:
            dp[i] = max(dp[i-L[A[j]-1]]+1, dp[i]) j range(m) range m if i-L[A[j]-1] < 0:
            None
        else:
            dp[i] = max(dp[i-L[A[j]-1]]+1, dp[i]) i-L[A[j]-1] < 0 i-L[A[j]-1] i L[A[j]-1] L A[j]-1 A[j] A j 1 0 None dp[i] = max(dp[i-L[A[j]-1]]+1, dp[i]) dp[i] dp i max(dp[i-L[A[j]-1]]+1, dp[i]) max dp[i-L[A[j]-1]]+1 dp[i-L[A[j]-1]] dp i-L[A[j]-1] i L[A[j]-1] L A[j]-1 A[j] A j 1 1 dp[i] dp i A.sort() A.sort A sort A.reverse() A.reverse A reverse cur = n cur n ans = '' ans '' while cur != 0:
    for i in range(m):
        temp = A[i]
        if cur-L[temp-1] >= 0:
            if dp[cur-L[temp-1]] == dp[cur]-1:
                ans = ans+str(temp)
                cur -= L[temp-1]
                break cur != 0 cur 0 for i in range(m):
        temp = A[i]
        if cur-L[temp-1] >= 0:
            if dp[cur-L[temp-1]] == dp[cur]-1:
                ans = ans+str(temp)
                cur -= L[temp-1]
                break i range(m) range m temp = A[i] temp A[i] A i if cur-L[temp-1] >= 0:
            if dp[cur-L[temp-1]] == dp[cur]-1:
                ans = ans+str(temp)
                cur -= L[temp-1]
                break cur-L[temp-1] >= 0 cur-L[temp-1] cur L[temp-1] L temp-1 temp 1 0 if dp[cur-L[temp-1]] == dp[cur]-1:
                ans = ans+str(temp)
                cur -= L[temp-1]
                break dp[cur-L[temp-1]] == dp[cur]-1 dp[cur-L[temp-1]] dp cur-L[temp-1] cur L[temp-1] L temp-1 temp 1 dp[cur]-1 dp[cur] dp cur 1 ans = ans+str(temp) ans ans+str(temp) ans str(temp) str temp cur -= L[temp-1] cur L[temp-1] L temp-1 temp 1 break print(ans) print ans dp = [-float('inf')]*(n+1) [-float('inf')]*(n+1) dp m = map(int,input().split()) map(int,input().split()) m n,m = map(int,input().split()) map(int,input().split()) n cur -= L[temp-1] L[temp-1] cur temp = A[i] A[i] temp ans = '' '' ans ans = ans+str(temp) ans+str(temp) ans A = list(map(int,input().split())) list(map(int,input().split())) A cur = n n cur 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())
A = list(map(int,input().split()))
L = [2,5,5,4,5,6,3,7,6]
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(1,n+1):
    for j in range(m):
        if i-L[A[j]-1] < 0:
            None
        else:
            dp[i] = max(dp[i-L[A[j]-1]]+1, dp[i])
A.sort()
A.reverse()
cur = n
ans = ''
while cur != 0:
    for i in range(m):
        temp = A[i]
        if cur-L[temp-1] >= 0:
            if dp[cur-L[temp-1]] == dp[cur]-1:
                ans = ans+str(temp)
                cur -= L[temp-1]
                break
print(ans)
