n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)
l = [0,2,5,5,4,5,6,3,7,6]

dp = [-1**10]*(n+1)
dp[0] = 0
for i in range(1,n+1):
    
    for j in range(m):
        if i >= l[a[j]] and dp[i] < dp[i-l[a[j]]]+1:
            dp[i] = dp[i-l[a[j]]]+1
            

ans = []
remain = dp[-1]
now = n
for i in a:
    x = l[i]
    while now -x >= 0 and dp[now] == dp[now-x]+1:
        ans.append(i)
        now -= x 
print(*ans,sep="") 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 l = [0,2,5,5,4,5,6,3,7,6] l [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp = [-1**10]*(n+1) dp [-1**10]*(n+1) [-1**10] -1**10 -1 10 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]] and dp[i] < dp[i-l[a[j]]]+1:
            dp[i] = dp[i-l[a[j]]]+1
             i range(1,n+1) range 1 n+1 n 1 for j in range(m):
        if i >= l[a[j]] and dp[i] < dp[i-l[a[j]]]+1:
            dp[i] = dp[i-l[a[j]]]+1
             j range(m) range m if i >= l[a[j]] and dp[i] < dp[i-l[a[j]]]+1:
            dp[i] = dp[i-l[a[j]]]+1
             i >= l[a[j]] and dp[i] < dp[i-l[a[j]]]+1 i >= l[a[j]] i l[a[j]] l a[j] a j dp[i] < dp[i-l[a[j]]]+1 dp[i] dp i dp[i-l[a[j]]]+1 dp[i-l[a[j]]] dp i-l[a[j]] i l[a[j]] l a[j] a j 1 dp[i] = dp[i-l[a[j]]]+1 dp[i] dp i dp[i-l[a[j]]]+1 dp[i-l[a[j]]] dp i-l[a[j]] i l[a[j]] l a[j] a j 1 ans = [] ans [] remain = dp[-1] remain dp[-1] dp -1 now = n now n for i in a:
    x = l[i]
    while now -x >= 0 and dp[now] == dp[now-x]+1:
        ans.append(i)
        now -= x  i a x = l[i] x l[i] l i while now -x >= 0 and dp[now] == dp[now-x]+1:
        ans.append(i)
        now -= x  now -x >= 0 and dp[now] == dp[now-x]+1 now -x >= 0 now -x now x 0 dp[now] == dp[now-x]+1 dp[now] dp now dp[now-x]+1 dp[now-x] dp now-x now x 1 ans.append(i) ans.append ans append i now -= x now x print(*ans,sep="") print *ans ans sep="" sep "" n,m = map(int,input().split()) map(int,input().split()) n remain = dp[-1] dp[-1] remain dp = [-1**10]*(n+1) [-1**10]*(n+1) dp now = n n now ans = [] [] ans now -= x x now l = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] l a = list(map(int,input().split())) list(map(int,input().split())) a x = l[i] l[i] x 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)
l = [0,2,5,5,4,5,6,3,7,6]

dp = [-1**10]*(n+1)
dp[0] = 0
for i in range(1,n+1):
    
    for j in range(m):
        if i >= l[a[j]] and dp[i] < dp[i-l[a[j]]]+1:
            dp[i] = dp[i-l[a[j]]]+1
            

ans = []
remain = dp[-1]
now = n
for i in a:
    x = l[i]
    while now -x >= 0 and dp[now] == dp[now-x]+1:
        ans.append(i)
        now -= x 
print(*ans,sep="")