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