n,m=map(int,input().split())
sz=[0,2,5,5,4,5,6,3,7,6]
l=[]
dp=[0]*(n+1)
l=list(map(int,input().split()))
l.sort(reverse=True)
dp[0]=1
for i in range(1,n+1):
    for j in l:
        if i-sz[j]>=0 and dp[i-sz[j]]>0:
            dp[i]=max(dp[i],1+dp[i-sz[j]])
#print(dp)
ans=[]
#using the dp table construct the number 
cur=n
while cur>0:#cur denotes count of available match sticks
 #   print(cur)
    for j in l:
        if cur-sz[j]>=0:
            if dp[cur]==1+dp[cur-sz[j]] and dp[cur-sz[j]]>0:
                ans.append(j)
                cur-=sz[j]
                break
ans.sort(reverse=True)
print(''.join(map(str,ans)))

 n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m sz=[0,2,5,5,4,5,6,3,7,6] sz [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 l=[] l [] dp=[0]*(n+1) dp [0]*(n+1) [0] 0 n+1 n 1 l=list(map(int,input().split())) l list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split l.sort(reverse=True) l.sort l sort reverse=True reverse True dp[0]=1 dp[0] dp 0 1 for i in range(1,n+1):
    for j in l:
        if i-sz[j]>=0 and dp[i-sz[j]]>0:
            dp[i]=max(dp[i],1+dp[i-sz[j]])
#print(dp) i range(1,n+1) range 1 n+1 n 1 for j in l:
        if i-sz[j]>=0 and dp[i-sz[j]]>0:
            dp[i]=max(dp[i],1+dp[i-sz[j]])
#print(dp) j l if i-sz[j]>=0 and dp[i-sz[j]]>0:
            dp[i]=max(dp[i],1+dp[i-sz[j]])
#print(dp) i-sz[j]>=0 and dp[i-sz[j]]>0 i-sz[j]>=0 i-sz[j] i sz[j] sz j 0 dp[i-sz[j]]>0 dp[i-sz[j]] dp i-sz[j] i sz[j] sz j 0 dp[i]=max(dp[i],1+dp[i-sz[j]]) dp[i] dp i max(dp[i],1+dp[i-sz[j]]) max dp[i] dp i 1+dp[i-sz[j]] 1 dp[i-sz[j]] dp i-sz[j] i sz[j] sz j ans=[] ans [] cur=n cur n while cur>0:#cur denotes count of available match sticks
 #   print(cur)
    for j in l:
        if cur-sz[j]>=0:
            if dp[cur]==1+dp[cur-sz[j]] and dp[cur-sz[j]]>0:
                ans.append(j)
                cur-=sz[j]
                break cur>0 cur 0 for j in l:
        if cur-sz[j]>=0:
            if dp[cur]==1+dp[cur-sz[j]] and dp[cur-sz[j]]>0:
                ans.append(j)
                cur-=sz[j]
                break j l if cur-sz[j]>=0:
            if dp[cur]==1+dp[cur-sz[j]] and dp[cur-sz[j]]>0:
                ans.append(j)
                cur-=sz[j]
                break cur-sz[j]>=0 cur-sz[j] cur sz[j] sz j 0 if dp[cur]==1+dp[cur-sz[j]] and dp[cur-sz[j]]>0:
                ans.append(j)
                cur-=sz[j]
                break dp[cur]==1+dp[cur-sz[j]] and dp[cur-sz[j]]>0 dp[cur]==1+dp[cur-sz[j]] dp[cur] dp cur 1+dp[cur-sz[j]] 1 dp[cur-sz[j]] dp cur-sz[j] cur sz[j] sz j dp[cur-sz[j]]>0 dp[cur-sz[j]] dp cur-sz[j] cur sz[j] sz j 0 ans.append(j) ans.append ans append j cur-=sz[j] cur sz[j] sz j break ans.sort(reverse=True) ans.sort ans sort reverse=True reverse True print(''.join(map(str,ans))) print ''.join(map(str,ans)) ''.join '' join map(str,ans) map str ans cur=n n cur l=[] [] l dp=[0]*(n+1) [0]*(n+1) dp l=list(map(int,input().split())) list(map(int,input().split())) l ans=[] [] ans sz=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] sz n,m=map(int,input().split()) map(int,input().split()) n m=map(int,input().split()) map(int,input().split()) m cur-=sz[j] sz[j] cur
n,m=map(int,input().split())
sz=[0,2,5,5,4,5,6,3,7,6]
l=[]
dp=[0]*(n+1)
l=list(map(int,input().split()))
l.sort(reverse=True)
dp[0]=1
for i in range(1,n+1):
    for j in l:
        if i-sz[j]>=0 and dp[i-sz[j]]>0:
            dp[i]=max(dp[i],1+dp[i-sz[j]])
#print(dp)
ans=[]
#using the dp table construct the number 
cur=n
while cur>0:#cur denotes count of available match sticks
 #   print(cur)
    for j in l:
        if cur-sz[j]>=0:
            if dp[cur]==1+dp[cur-sz[j]] and dp[cur-sz[j]]>0:
                ans.append(j)
                cur-=sz[j]
                break
ans.sort(reverse=True)
print(''.join(map(str,ans)))


