n,m=map(int, input().split())
lst=list(map(int,input().split()))
weight=[0,2,5,5,4,5,6,3,7,6]
DP=[-1]*(n+1)
DP[0]=0
for i in range(n+1):
  for x in lst:
    if i+weight[x]<n+1:
      DP[i+weight[x]]=max(DP[i+weight[x]], DP[i]*10+x)
print(DP[n]) n,m=map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m lst=list(map(int,input().split())) lst list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split weight=[0,2,5,5,4,5,6,3,7,6] weight [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 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 x in lst:
    if i+weight[x]<n+1:
      DP[i+weight[x]]=max(DP[i+weight[x]], DP[i]*10+x) i range(n+1) range n+1 n 1 for x in lst:
    if i+weight[x]<n+1:
      DP[i+weight[x]]=max(DP[i+weight[x]], DP[i]*10+x) x lst if i+weight[x]<n+1:
      DP[i+weight[x]]=max(DP[i+weight[x]], DP[i]*10+x) i+weight[x]<n+1 i+weight[x] i weight[x] weight x n+1 n 1 DP[i+weight[x]]=max(DP[i+weight[x]], DP[i]*10+x) DP[i+weight[x]] DP i+weight[x] i weight[x] weight x max(DP[i+weight[x]], DP[i]*10+x) max DP[i+weight[x]] DP i+weight[x] i weight[x] weight x DP[i]*10+x DP[i]*10 DP[i] DP i 10 x print(DP[n]) print DP[n] DP n DP=[-1]*(n+1) [-1]*(n+1) DP lst=list(map(int,input().split())) list(map(int,input().split())) lst n,m=map(int, input().split()) map(int, input().split()) n m=map(int, input().split()) map(int, input().split()) m weight=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] weight
n,m=map(int, input().split())
lst=list(map(int,input().split()))
weight=[0,2,5,5,4,5,6,3,7,6]
DP=[-1]*(n+1)
DP[0]=0
for i in range(n+1):
  for x in lst:
    if i+weight[x]<n+1:
      DP[i+weight[x]]=max(DP[i+weight[x]], DP[i]*10+x)
print(DP[n])