n,m,*a=map(int,open(0).read().split())
d=[]
for i,j in((7,3),(9,6),(8,7),(6,6),(5,5),(4,4),(3,5),(1,2),(2,5)):
    if i in a:
        d.append((i,j))
dp=[0]*-~n
for i in range(1,n+1):
    for j,k in d:
        if i-k<0 or i-k!=0 and not dp[i-k]:continue
        dp[i]=max(dp[i],dp[i-k]*10+j)
print(dp[n]) n,m,*a=map(int,open(0).read().split()) n map(int,open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split m *a a d=[] d [] for i,j in((7,3),(9,6),(8,7),(6,6),(5,5),(4,4),(3,5),(1,2),(2,5)):
    if i in a:
        d.append((i,j)) i j ((7,3),(9,6),(8,7),(6,6),(5,5),(4,4),(3,5),(1,2),(2,5)) (7,3) 7 3 (9,6) 9 6 (8,7) 8 7 (6,6) 6 6 (5,5) 5 5 (4,4) 4 4 (3,5) 3 5 (1,2) 1 2 (2,5) 2 5 if i in a:
        d.append((i,j)) i in a i a d.append((i,j)) d.append d append (i,j) i j dp=[0]*-~n dp [0]*-~n [0] 0 -~n ~n n for i in range(1,n+1):
    for j,k in d:
        if i-k<0 or i-k!=0 and not dp[i-k]:continue
        dp[i]=max(dp[i],dp[i-k]*10+j) i range(1,n+1) range 1 n+1 n 1 for j,k in d:
        if i-k<0 or i-k!=0 and not dp[i-k]:continue
        dp[i]=max(dp[i],dp[i-k]*10+j) j k d if i-k<0 or i-k!=0 and not dp[i-k]:continue
         i-k<0 or i-k!=0 and not dp[i-k] i-k<0 i-k i k 0 i-k!=0 and not dp[i-k] i-k!=0 i-k i k 0 not dp[i-k] dp[i-k] dp i-k i k dp[i]=max(dp[i],dp[i-k]*10+j) dp[i] dp i max(dp[i],dp[i-k]*10+j) max dp[i] dp i dp[i-k]*10+j dp[i-k]*10 dp[i-k] dp i-k i k 10 j print(dp[n]) print dp[n] dp n m,*a=map(int,open(0).read().split()) map(int,open(0).read().split()) m d=[] [] d dp=[0]*-~n [0]*-~n dp n,m,*a=map(int,open(0).read().split()) map(int,open(0).read().split()) n
n,m,*a=map(int,open(0).read().split())
d=[]
for i,j in((7,3),(9,6),(8,7),(6,6),(5,5),(4,4),(3,5),(1,2),(2,5)):
    if i in a:
        d.append((i,j))
dp=[0]*-~n
for i in range(1,n+1):
    for j,k in d:
        if i-k<0 or i-k!=0 and not dp[i-k]:continue
        dp[i]=max(dp[i],dp[i-k]*10+j)
print(dp[n])