n,m=map(int,input().split())
a=list(map(int,input().split()))
x=[2,5,5,4,5,6,3,7,6]
dp=[0 for i in range(n+1)]
for i in range(1,n+1):
  l=[-99999999]
  for j in range(m):
    if i-x[a[j]-1]>=0:
      l.append(dp[i-x[a[j]-1]]+1)
  dp[i]=max(l)

a.sort()
a.reverse()
ans=[]
y=n
for i in range(dp[n],0,-1):
  for j in range(m):
    if y-x[a[j]-1]>=0:
      if dp[y-x[a[j]-1]]>=i-1:
        ans.append(str(a[j]))
        y-=x[a[j]-1]
        break
print(''.join(ans)) 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 x=[2,5,5,4,5,6,3,7,6] x [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 0 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) 0 dp=[0 for i in range(n+1)] dp [0 for i in range(n+1)] for i in range(1,n+1):
  l=[-99999999]
  for j in range(m):
    if i-x[a[j]-1]>=0:
      l.append(dp[i-x[a[j]-1]]+1)
  dp[i]=max(l) i range(1,n+1) range 1 n+1 n 1 l=[-99999999] l [-99999999] -99999999 for j in range(m):
    if i-x[a[j]-1]>=0:
      l.append(dp[i-x[a[j]-1]]+1)
   j range(m) range m if i-x[a[j]-1]>=0:
      l.append(dp[i-x[a[j]-1]]+1)
   i-x[a[j]-1]>=0 i-x[a[j]-1] i x[a[j]-1] x a[j]-1 a[j] a j 1 0 l.append(dp[i-x[a[j]-1]]+1) l.append l append dp[i-x[a[j]-1]]+1 dp[i-x[a[j]-1]] dp i-x[a[j]-1] i x[a[j]-1] x a[j]-1 a[j] a j 1 1 dp[i]=max(l) dp[i] dp i max(l) max l a.sort() a.sort a sort a.reverse() a.reverse a reverse ans=[] ans [] y=n y n for i in range(dp[n],0,-1):
  for j in range(m):
    if y-x[a[j]-1]>=0:
      if dp[y-x[a[j]-1]]>=i-1:
        ans.append(str(a[j]))
        y-=x[a[j]-1]
        break i range(dp[n],0,-1) range dp[n] dp n 0 -1 for j in range(m):
    if y-x[a[j]-1]>=0:
      if dp[y-x[a[j]-1]]>=i-1:
        ans.append(str(a[j]))
        y-=x[a[j]-1]
        break j range(m) range m if y-x[a[j]-1]>=0:
      if dp[y-x[a[j]-1]]>=i-1:
        ans.append(str(a[j]))
        y-=x[a[j]-1]
        break y-x[a[j]-1]>=0 y-x[a[j]-1] y x[a[j]-1] x a[j]-1 a[j] a j 1 0 if dp[y-x[a[j]-1]]>=i-1:
        ans.append(str(a[j]))
        y-=x[a[j]-1]
        break dp[y-x[a[j]-1]]>=i-1 dp[y-x[a[j]-1]] dp y-x[a[j]-1] y x[a[j]-1] x a[j]-1 a[j] a j 1 i-1 i 1 ans.append(str(a[j])) ans.append ans append str(a[j]) str a[j] a j y-=x[a[j]-1] y x[a[j]-1] x a[j]-1 a[j] a j 1 break print(''.join(ans)) print ''.join(ans) ''.join '' join ans l=[-99999999] [-99999999] l ans=[] [] ans x=[2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] x n,m=map(int,input().split()) map(int,input().split()) n m=map(int,input().split()) map(int,input().split()) m y=n n y a=list(map(int,input().split())) list(map(int,input().split())) a y-=x[a[j]-1] x[a[j]-1] y dp=[0 for i in range(n+1)] [0 for i in range(n+1)] dp
n,m=map(int,input().split())
a=list(map(int,input().split()))
x=[2,5,5,4,5,6,3,7,6]
dp=[0 for i in range(n+1)]
for i in range(1,n+1):
  l=[-99999999]
  for j in range(m):
    if i-x[a[j]-1]>=0:
      l.append(dp[i-x[a[j]-1]]+1)
  dp[i]=max(l)

a.sort()
a.reverse()
ans=[]
y=n
for i in range(dp[n],0,-1):
  for j in range(m):
    if y-x[a[j]-1]>=0:
      if dp[y-x[a[j]-1]]>=i-1:
        ans.append(str(a[j]))
        y-=x[a[j]-1]
        break
print(''.join(ans))