n,m=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
dic={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[-1]*(n+1)
dp[0]=0
for i in range(n+1):
  for val in arr:
    if i-dic[val]<0:
      continue
    else:
      dp[i]=max(dp[i],dp[i-dic[val]]+1)
ans=''
tmp=n
while tmp>0:
  for val in arr:
    if tmp-dic[val]<0:
      continue
    if dp[tmp]==dp[tmp-dic[val]]+1 and dp[tmp-dic[val]]!=-1:
      ans+=str(val)
      tmp-=dic[val]
      break
print(ans) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m arr=list(map(int,input().split())) arr list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split arr=sorted(arr,reverse=True) arr sorted(arr,reverse=True) sorted arr reverse=True reverse True dic={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} dic {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 dp=[-1]*(n+1) dp [-1]*(n+1) [-1] -1 n+1 n 1 dp[0]=0 dp[0] dp 0 0 for i in range(n+1):
  for val in arr:
    if i-dic[val]<0:
      continue
    else:
      dp[i]=max(dp[i],dp[i-dic[val]]+1) i range(n+1) range n+1 n 1 for val in arr:
    if i-dic[val]<0:
      continue
    else:
      dp[i]=max(dp[i],dp[i-dic[val]]+1) val arr if i-dic[val]<0:
      continue
    else:
      dp[i]=max(dp[i],dp[i-dic[val]]+1) i-dic[val]<0 i-dic[val] i dic[val] dic val 0 continue dp[i]=max(dp[i],dp[i-dic[val]]+1) dp[i] dp i max(dp[i],dp[i-dic[val]]+1) max dp[i] dp i dp[i-dic[val]]+1 dp[i-dic[val]] dp i-dic[val] i dic[val] dic val 1 ans='' ans '' tmp=n tmp n while tmp>0:
  for val in arr:
    if tmp-dic[val]<0:
      continue
    if dp[tmp]==dp[tmp-dic[val]]+1 and dp[tmp-dic[val]]!=-1:
      ans+=str(val)
      tmp-=dic[val]
      break tmp>0 tmp 0 for val in arr:
    if tmp-dic[val]<0:
      continue
    if dp[tmp]==dp[tmp-dic[val]]+1 and dp[tmp-dic[val]]!=-1:
      ans+=str(val)
      tmp-=dic[val]
      break val arr if tmp-dic[val]<0:
      continue
     tmp-dic[val]<0 tmp-dic[val] tmp dic[val] dic val 0 continue if dp[tmp]==dp[tmp-dic[val]]+1 and dp[tmp-dic[val]]!=-1:
      ans+=str(val)
      tmp-=dic[val]
      break dp[tmp]==dp[tmp-dic[val]]+1 and dp[tmp-dic[val]]!=-1 dp[tmp]==dp[tmp-dic[val]]+1 dp[tmp] dp tmp dp[tmp-dic[val]]+1 dp[tmp-dic[val]] dp tmp-dic[val] tmp dic[val] dic val 1 dp[tmp-dic[val]]!=-1 dp[tmp-dic[val]] dp tmp-dic[val] tmp dic[val] dic val -1 ans+=str(val) ans str(val) str val tmp-=dic[val] tmp dic[val] dic val break print(ans) print ans dp=[-1]*(n+1) [-1]*(n+1) dp tmp=n n tmp ans+=str(val) str(val) ans n,m=map(int,input().split()) map(int,input().split()) n arr=sorted(arr,reverse=True) sorted(arr,reverse=True) arr m=map(int,input().split()) map(int,input().split()) m arr=list(map(int,input().split())) list(map(int,input().split())) arr dic={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} dic tmp-=dic[val] dic[val] tmp ans='' '' ans
n,m=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
dic={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[-1]*(n+1)
dp[0]=0
for i in range(n+1):
  for val in arr:
    if i-dic[val]<0:
      continue
    else:
      dp[i]=max(dp[i],dp[i-dic[val]]+1)
ans=''
tmp=n
while tmp>0:
  for val in arr:
    if tmp-dic[val]<0:
      continue
    if dp[tmp]==dp[tmp-dic[val]]+1 and dp[tmp-dic[val]]!=-1:
      ans+=str(val)
      tmp-=dic[val]
      break
print(ans)