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