N,M=map(int,input().split())
l=list(map(int,input().split()))
w=[2,5,5,4,5,6,3,7,6]
l.sort()
dp=[0]*(max(N+1,8))
for j in l:
   dp[w[j-1]]=j
for i in range(N):
   if dp[i]!=0:
      for j in l:
         if w[j-1]+i<=N:
            dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j)
print(dp[N]) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M l=list(map(int,input().split())) l list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split w=[2,5,5,4,5,6,3,7,6] w [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 l.sort() l.sort l sort dp=[0]*(max(N+1,8)) dp [0]*(max(N+1,8)) [0] 0 max(N+1,8) max N+1 N 1 8 for j in l:
   dp[w[j-1]]=j j l dp[w[j-1]]=j dp[w[j-1]] dp w[j-1] w j-1 j 1 j for i in range(N):
   if dp[i]!=0:
      for j in l:
         if w[j-1]+i<=N:
            dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j) i range(N) range N if dp[i]!=0:
      for j in l:
         if w[j-1]+i<=N:
            dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j) dp[i]!=0 dp[i] dp i 0 for j in l:
         if w[j-1]+i<=N:
            dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j) j l if w[j-1]+i<=N:
            dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j) w[j-1]+i<=N w[j-1]+i w[j-1] w j-1 j 1 i N dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j) dp[i+w[j-1]] dp i+w[j-1] i w[j-1] w j-1 j 1 max(dp[i+w[j-1]],dp[i]*10+j) max dp[i+w[j-1]] dp i+w[j-1] i w[j-1] w j-1 j 1 dp[i]*10+j dp[i]*10 dp[i] dp i 10 j print(dp[N]) print dp[N] dp N l=list(map(int,input().split())) list(map(int,input().split())) l N,M=map(int,input().split()) map(int,input().split()) N M=map(int,input().split()) map(int,input().split()) M dp=[0]*(max(N+1,8)) [0]*(max(N+1,8)) dp w=[2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] w
N,M=map(int,input().split())
l=list(map(int,input().split()))
w=[2,5,5,4,5,6,3,7,6]
l.sort()
dp=[0]*(max(N+1,8))
for j in l:
   dp[w[j-1]]=j
for i in range(N):
   if dp[i]!=0:
      for j in l:
         if w[j-1]+i<=N:
            dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j)
print(dp[N])