n,m=map(int,input().split())
A=[int(i) for i in input().split()]
if 2 in A and 3 in A:
  A.remove(2)
if 3 in A and 5 in A:
  A.remove(3)
if 2 in A and 5 in A:
  A.remove(2)
if 6 in A and 9 in A:
  A.remove(6)
m=len(A)
D={}
D[1]=2
D[2]=5
D[3]=5
D[4]=4
D[5]=5
D[6]=6
D[7]=3
D[8]=7
D[9]=6
DP=[-float("inf")]*(n+1)
DP[0]=0
for i in range(n):
  for j in range(m):
    if D[A[j]]<=i+1 and DP[i+1-D[A[j]]]!=float("inf") and DP[i+1-D[A[j]]]+1>=DP[i+1]:
      DP[i+1]=DP[i+1-D[A[j]]]+1
A.sort(reverse=True)
k=DP[n]
ans=""
cur=n
for _ in range(k):
  for j in range(m):
    if cur>=D[A[j]] and DP[cur-D[A[j]]]==DP[cur]-1:
      ans+=str(A[j])
      cur-=D[A[j]]
      break
print(ans) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A=[int(i) for i in input().split()] A [int(i) for i in input().split()] if 2 in A and 3 in A:
  A.remove(2) 2 in A and 3 in A 2 in A 2 A 3 in A 3 A A.remove(2) A.remove A remove 2 if 3 in A and 5 in A:
  A.remove(3) 3 in A and 5 in A 3 in A 3 A 5 in A 5 A A.remove(3) A.remove A remove 3 if 2 in A and 5 in A:
  A.remove(2) 2 in A and 5 in A 2 in A 2 A 5 in A 5 A A.remove(2) A.remove A remove 2 if 6 in A and 9 in A:
  A.remove(6) 6 in A and 9 in A 6 in A 6 A 9 in A 9 A A.remove(6) A.remove A remove 6 m=len(A) m len(A) len A D={} D {} D[1]=2 D[1] D 1 2 D[2]=5 D[2] D 2 5 D[3]=5 D[3] D 3 5 D[4]=4 D[4] D 4 4 D[5]=5 D[5] D 5 5 D[6]=6 D[6] D 6 6 D[7]=3 D[7] D 7 3 D[8]=7 D[8] D 8 7 D[9]=6 D[9] D 9 6 DP=[-float("inf")]*(n+1) DP [-float("inf")]*(n+1) [-float("inf")] -float("inf") float("inf") float "inf" n+1 n 1 DP[0]=0 DP[0] DP 0 0 for i in range(n):
  for j in range(m):
    if D[A[j]]<=i+1 and DP[i+1-D[A[j]]]!=float("inf") and DP[i+1-D[A[j]]]+1>=DP[i+1]:
      DP[i+1]=DP[i+1-D[A[j]]]+1 i range(n) range n for j in range(m):
    if D[A[j]]<=i+1 and DP[i+1-D[A[j]]]!=float("inf") and DP[i+1-D[A[j]]]+1>=DP[i+1]:
      DP[i+1]=DP[i+1-D[A[j]]]+1 j range(m) range m if D[A[j]]<=i+1 and DP[i+1-D[A[j]]]!=float("inf") and DP[i+1-D[A[j]]]+1>=DP[i+1]:
      DP[i+1]=DP[i+1-D[A[j]]]+1 D[A[j]]<=i+1 and DP[i+1-D[A[j]]]!=float("inf") and DP[i+1-D[A[j]]]+1>=DP[i+1] D[A[j]]<=i+1 and DP[i+1-D[A[j]]]!=float("inf") D[A[j]]<=i+1 D[A[j]] D A[j] A j i+1 i 1 DP[i+1-D[A[j]]]!=float("inf") DP[i+1-D[A[j]]] DP i+1-D[A[j]] i+1 i 1 D[A[j]] D A[j] A j float("inf") float "inf" DP[i+1-D[A[j]]]+1>=DP[i+1] DP[i+1-D[A[j]]]+1 DP[i+1-D[A[j]]] DP i+1-D[A[j]] i+1 i 1 D[A[j]] D A[j] A j 1 DP[i+1] DP i+1 i 1 DP[i+1]=DP[i+1-D[A[j]]]+1 DP[i+1] DP i+1 i 1 DP[i+1-D[A[j]]]+1 DP[i+1-D[A[j]]] DP i+1-D[A[j]] i+1 i 1 D[A[j]] D A[j] A j 1 A.sort(reverse=True) A.sort A sort reverse=True reverse True k=DP[n] k DP[n] DP n ans="" ans "" cur=n cur n for _ in range(k):
  for j in range(m):
    if cur>=D[A[j]] and DP[cur-D[A[j]]]==DP[cur]-1:
      ans+=str(A[j])
      cur-=D[A[j]]
      break _ range(k) range k for j in range(m):
    if cur>=D[A[j]] and DP[cur-D[A[j]]]==DP[cur]-1:
      ans+=str(A[j])
      cur-=D[A[j]]
      break j range(m) range m if cur>=D[A[j]] and DP[cur-D[A[j]]]==DP[cur]-1:
      ans+=str(A[j])
      cur-=D[A[j]]
      break cur>=D[A[j]] and DP[cur-D[A[j]]]==DP[cur]-1 cur>=D[A[j]] cur D[A[j]] D A[j] A j DP[cur-D[A[j]]]==DP[cur]-1 DP[cur-D[A[j]]] DP cur-D[A[j]] cur D[A[j]] D A[j] A j DP[cur]-1 DP[cur] DP cur 1 ans+=str(A[j]) ans str(A[j]) str A[j] A j cur-=D[A[j]] cur D[A[j]] D A[j] A j break print(ans) print ans n,m=map(int,input().split()) map(int,input().split()) n m=len(A) len(A) m cur=n n cur A=[int(i) for i in input().split()] [int(i) for i in input().split()] A ans="" "" ans D={} {} D DP=[-float("inf")]*(n+1) [-float("inf")]*(n+1) DP k=DP[n] DP[n] k m=map(int,input().split()) map(int,input().split()) m ans+=str(A[j]) str(A[j]) ans cur-=D[A[j]] D[A[j]] cur
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
if 2 in A and 3 in A:
  A.remove(2)
if 3 in A and 5 in A:
  A.remove(3)
if 2 in A and 5 in A:
  A.remove(2)
if 6 in A and 9 in A:
  A.remove(6)
m=len(A)
D={}
D[1]=2
D[2]=5
D[3]=5
D[4]=4
D[5]=5
D[6]=6
D[7]=3
D[8]=7
D[9]=6
DP=[-float("inf")]*(n+1)
DP[0]=0
for i in range(n):
  for j in range(m):
    if D[A[j]]<=i+1 and DP[i+1-D[A[j]]]!=float("inf") and DP[i+1-D[A[j]]]+1>=DP[i+1]:
      DP[i+1]=DP[i+1-D[A[j]]]+1
A.sort(reverse=True)
k=DP[n]
ans=""
cur=n
for _ in range(k):
  for j in range(m):
    if cur>=D[A[j]] and DP[cur-D[A[j]]]==DP[cur]-1:
      ans+=str(A[j])
      cur-=D[A[j]]
      break
print(ans)