n,m=map(int,input().split())
A=[2,5,5,4,5,6,3,7,6]
B=list(map(int,input().split()))
B=sorted(B,reverse=True)
C=[]
for i in range(m):
  C.append(A[B[i]-1])
C=set(C)
C=sorted(list(C))
dp=[-10**10]*(n+10)
dp[0]=0
for i in range(1,n+1):
  for j in range(len(C)):
    if dp[i]<dp[i-C[j]]+1:
      dp[i]=dp[i-C[j]]+1
S=[]
for i in range(dp[n]):
  for j in range(len(B)):
    if dp[n-A[B[j]-1]]==dp[n]-1:
      n=n-A[B[j]-1]
      S.append(B[j])
      break
for i in range(len(S)):
  print(S[i],end="")
print() n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m A=[2,5,5,4,5,6,3,7,6] A [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 B=list(map(int,input().split())) B list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split B=sorted(B,reverse=True) B sorted(B,reverse=True) sorted B reverse=True reverse True C=[] C [] for i in range(m):
  C.append(A[B[i]-1]) i range(m) range m C.append(A[B[i]-1]) C.append C append A[B[i]-1] A B[i]-1 B[i] B i 1 C=set(C) C set(C) set C C=sorted(list(C)) C sorted(list(C)) sorted list(C) list C dp=[-10**10]*(n+10) dp [-10**10]*(n+10) [-10**10] -10**10 -10 10 n+10 n 10 dp[0]=0 dp[0] dp 0 0 for i in range(1,n+1):
  for j in range(len(C)):
    if dp[i]<dp[i-C[j]]+1:
      dp[i]=dp[i-C[j]]+1 i range(1,n+1) range 1 n+1 n 1 for j in range(len(C)):
    if dp[i]<dp[i-C[j]]+1:
      dp[i]=dp[i-C[j]]+1 j range(len(C)) range len(C) len C if dp[i]<dp[i-C[j]]+1:
      dp[i]=dp[i-C[j]]+1 dp[i]<dp[i-C[j]]+1 dp[i] dp i dp[i-C[j]]+1 dp[i-C[j]] dp i-C[j] i C[j] C j 1 dp[i]=dp[i-C[j]]+1 dp[i] dp i dp[i-C[j]]+1 dp[i-C[j]] dp i-C[j] i C[j] C j 1 S=[] S [] for i in range(dp[n]):
  for j in range(len(B)):
    if dp[n-A[B[j]-1]]==dp[n]-1:
      n=n-A[B[j]-1]
      S.append(B[j])
      break i range(dp[n]) range dp[n] dp n for j in range(len(B)):
    if dp[n-A[B[j]-1]]==dp[n]-1:
      n=n-A[B[j]-1]
      S.append(B[j])
      break j range(len(B)) range len(B) len B if dp[n-A[B[j]-1]]==dp[n]-1:
      n=n-A[B[j]-1]
      S.append(B[j])
      break dp[n-A[B[j]-1]]==dp[n]-1 dp[n-A[B[j]-1]] dp n-A[B[j]-1] n A[B[j]-1] A B[j]-1 B[j] B j 1 dp[n]-1 dp[n] dp n 1 n=n-A[B[j]-1] n n-A[B[j]-1] n A[B[j]-1] A B[j]-1 B[j] B j 1 S.append(B[j]) S.append S append B[j] B j break for i in range(len(S)):
  print(S[i],end="") i range(len(S)) range len(S) len S print(S[i],end="") print S[i] S i end="" end "" print() print C=sorted(list(C)) sorted(list(C)) C S=[] [] S C=[] [] C dp=[-10**10]*(n+10) [-10**10]*(n+10) dp n,m=map(int,input().split()) map(int,input().split()) n B=sorted(B,reverse=True) sorted(B,reverse=True) B C=set(C) set(C) C A=[2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] A B=list(map(int,input().split())) list(map(int,input().split())) B m=map(int,input().split()) map(int,input().split()) m n=n-A[B[j]-1] n-A[B[j]-1] n
n,m=map(int,input().split())
A=[2,5,5,4,5,6,3,7,6]
B=list(map(int,input().split()))
B=sorted(B,reverse=True)
C=[]
for i in range(m):
  C.append(A[B[i]-1])
C=set(C)
C=sorted(list(C))
dp=[-10**10]*(n+10)
dp[0]=0
for i in range(1,n+1):
  for j in range(len(C)):
    if dp[i]<dp[i-C[j]]+1:
      dp[i]=dp[i-C[j]]+1
S=[]
for i in range(dp[n]):
  for j in range(len(B)):
    if dp[n-A[B[j]-1]]==dp[n]-1:
      n=n-A[B[j]-1]
      S.append(B[j])
      break
for i in range(len(S)):
  print(S[i],end="")
print()