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