N,M=map(int,input().split())
alist=list(map(int,input().split()))

blist=[False]*10
for a in alist:
  blist[a] = True

match=[6,2,5,5,4,5,6,3,7,6]
dp=[-1]*(N+1)

dp[0]=0
dp[1]=-1
for i in range(N+1):
  for j in range(1,10):
    if blist[j] and i+match[j]<=N:
      if dp[i+match[j]] < dp[i]+1:
        dp[i+match[j]] = dp[i]+1
#print(dp)

answer_str = ""
while(N>0):
  for i in reversed(range(1,10)):
    if blist[i] and N-match[i] >= 0 and dp[N-match[i]] == dp[N]-1:
      answer_str += str(i)
      N -= match[i]
      break
      
print(answer_str) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M alist=list(map(int,input().split())) alist list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split blist=[False]*10 blist [False]*10 [False] False 10 for a in alist:
  blist[a] = True a alist blist[a] = True blist[a] blist a True match=[6,2,5,5,4,5,6,3,7,6] match [6,2,5,5,4,5,6,3,7,6] 6 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 dp[1]=-1 dp[1] dp 1 -1 for i in range(N+1):
  for j in range(1,10):
    if blist[j] and i+match[j]<=N:
      if dp[i+match[j]] < dp[i]+1:
        dp[i+match[j]] = dp[i]+1
#print(dp) i range(N+1) range N+1 N 1 for j in range(1,10):
    if blist[j] and i+match[j]<=N:
      if dp[i+match[j]] < dp[i]+1:
        dp[i+match[j]] = dp[i]+1
#print(dp) j range(1,10) range 1 10 if blist[j] and i+match[j]<=N:
      if dp[i+match[j]] < dp[i]+1:
        dp[i+match[j]] = dp[i]+1
#print(dp) blist[j] and i+match[j]<=N blist[j] blist j i+match[j]<=N i+match[j] i match[j] match j N if dp[i+match[j]] < dp[i]+1:
        dp[i+match[j]] = dp[i]+1
#print(dp) dp[i+match[j]] < dp[i]+1 dp[i+match[j]] dp i+match[j] i match[j] match j dp[i]+1 dp[i] dp i 1 dp[i+match[j]] = dp[i]+1 dp[i+match[j]] dp i+match[j] i match[j] match j dp[i]+1 dp[i] dp i 1 answer_str = "" answer_str "" while(N>0):
  for i in reversed(range(1,10)):
    if blist[i] and N-match[i] >= 0 and dp[N-match[i]] == dp[N]-1:
      answer_str += str(i)
      N -= match[i]
      break
       N>0 N 0 for i in reversed(range(1,10)):
    if blist[i] and N-match[i] >= 0 and dp[N-match[i]] == dp[N]-1:
      answer_str += str(i)
      N -= match[i]
      break
       i reversed(range(1,10)) reversed range(1,10) range 1 10 if blist[i] and N-match[i] >= 0 and dp[N-match[i]] == dp[N]-1:
      answer_str += str(i)
      N -= match[i]
      break
       blist[i] and N-match[i] >= 0 and dp[N-match[i]] == dp[N]-1 blist[i] and N-match[i] >= 0 blist[i] blist i N-match[i] >= 0 N-match[i] N match[i] match i 0 dp[N-match[i]] == dp[N]-1 dp[N-match[i]] dp N-match[i] N match[i] match i dp[N]-1 dp[N] dp N 1 answer_str += str(i) answer_str str(i) str i N -= match[i] N match[i] match i break print(answer_str) print answer_str N,M=map(int,input().split()) map(int,input().split()) N answer_str += str(i) str(i) answer_str dp=[-1]*(N+1) [-1]*(N+1) dp match=[6,2,5,5,4,5,6,3,7,6] [6,2,5,5,4,5,6,3,7,6] match alist=list(map(int,input().split())) list(map(int,input().split())) alist answer_str = "" "" answer_str blist=[False]*10 [False]*10 blist M=map(int,input().split()) map(int,input().split()) M N -= match[i] match[i] N
N,M=map(int,input().split())
alist=list(map(int,input().split()))

blist=[False]*10
for a in alist:
  blist[a] = True

match=[6,2,5,5,4,5,6,3,7,6]
dp=[-1]*(N+1)

dp[0]=0
dp[1]=-1
for i in range(N+1):
  for j in range(1,10):
    if blist[j] and i+match[j]<=N:
      if dp[i+match[j]] < dp[i]+1:
        dp[i+match[j]] = dp[i]+1
#print(dp)

answer_str = ""
while(N>0):
  for i in reversed(range(1,10)):
    if blist[i] and N-match[i] >= 0 and dp[N-match[i]] == dp[N]-1:
      answer_str += str(i)
      N -= match[i]
      break
      
print(answer_str)