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