n,m=map(int,input().split())
A=reversed(sorted(map(int,input().split())))
M=[2,5,5,4,5,6,3,7,6]
D={}
E={}
for a in A:
    if M[a-1] in D:
        continue
    else:
        D[M[a-1]]=a
        E[a]=M[a-1]
S=list(reversed(sorted(E)))
        
dp=[0]*(n+2)
for i in range(1,n+2):
    cnt=-1
    for d in D:
        if i-d>=0:
            if dp[i-d]!=-1:
                cnt=max(dp[i-d]+1,cnt)
    dp[i]=cnt    
k=dp[n]
ans=""

while k>0:
    for s in S:
        x=E[s]
        if n-x<0:
            continue
        if dp[n-x]==k-1:
            ans+=str(s)
            k-=1
            n-=x
            break
print(ans) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m A=reversed(sorted(map(int,input().split()))) A reversed(sorted(map(int,input().split()))) reversed sorted(map(int,input().split())) sorted map(int,input().split()) map int input().split() ().split () input split M=[2,5,5,4,5,6,3,7,6] M [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 D={} D {} E={} E {} for a in A:
    if M[a-1] in D:
        continue
    else:
        D[M[a-1]]=a
        E[a]=M[a-1] a A if M[a-1] in D:
        continue
    else:
        D[M[a-1]]=a
        E[a]=M[a-1] M[a-1] in D M[a-1] M a-1 a 1 D continue D[M[a-1]]=a D[M[a-1]] D M[a-1] M a-1 a 1 a E[a]=M[a-1] E[a] E a M[a-1] M a-1 a 1 S=list(reversed(sorted(E))) S list(reversed(sorted(E))) list reversed(sorted(E)) reversed sorted(E) sorted E dp=[0]*(n+2) dp [0]*(n+2) [0] 0 n+2 n 2 for i in range(1,n+2):
    cnt=-1
    for d in D:
        if i-d>=0:
            if dp[i-d]!=-1:
                cnt=max(dp[i-d]+1,cnt)
    dp[i]=cnt     i range(1,n+2) range 1 n+2 n 2 cnt=-1 cnt -1 for d in D:
        if i-d>=0:
            if dp[i-d]!=-1:
                cnt=max(dp[i-d]+1,cnt)
     d D if i-d>=0:
            if dp[i-d]!=-1:
                cnt=max(dp[i-d]+1,cnt)
     i-d>=0 i-d i d 0 if dp[i-d]!=-1:
                cnt=max(dp[i-d]+1,cnt)
     dp[i-d]!=-1 dp[i-d] dp i-d i d -1 cnt=max(dp[i-d]+1,cnt) cnt max(dp[i-d]+1,cnt) max dp[i-d]+1 dp[i-d] dp i-d i d 1 cnt dp[i]=cnt dp[i] dp i cnt k=dp[n] k dp[n] dp n ans="" ans "" while k>0:
    for s in S:
        x=E[s]
        if n-x<0:
            continue
        if dp[n-x]==k-1:
            ans+=str(s)
            k-=1
            n-=x
            break k>0 k 0 for s in S:
        x=E[s]
        if n-x<0:
            continue
        if dp[n-x]==k-1:
            ans+=str(s)
            k-=1
            n-=x
            break s S x=E[s] x E[s] E s if n-x<0:
            continue
         n-x<0 n-x n x 0 continue if dp[n-x]==k-1:
            ans+=str(s)
            k-=1
            n-=x
            break dp[n-x]==k-1 dp[n-x] dp n-x n x k-1 k 1 ans+=str(s) ans str(s) str s k-=1 k 1 n-=x n x break print(ans) print ans k=dp[n] dp[n] k A=reversed(sorted(map(int,input().split()))) reversed(sorted(map(int,input().split()))) A ans="" "" ans D={} {} D E={} {} E M=[2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] M m=map(int,input().split()) map(int,input().split()) m k-=1 1 k x=E[s] E[s] x n,m=map(int,input().split()) map(int,input().split()) n ans+=str(s) str(s) ans dp=[0]*(n+2) [0]*(n+2) dp cnt=-1 -1 cnt S=list(reversed(sorted(E))) list(reversed(sorted(E))) S n-=x x n cnt=max(dp[i-d]+1,cnt) max(dp[i-d]+1,cnt) cnt
n,m=map(int,input().split())
A=reversed(sorted(map(int,input().split())))
M=[2,5,5,4,5,6,3,7,6]
D={}
E={}
for a in A:
    if M[a-1] in D:
        continue
    else:
        D[M[a-1]]=a
        E[a]=M[a-1]
S=list(reversed(sorted(E)))
        
dp=[0]*(n+2)
for i in range(1,n+2):
    cnt=-1
    for d in D:
        if i-d>=0:
            if dp[i-d]!=-1:
                cnt=max(dp[i-d]+1,cnt)
    dp[i]=cnt    
k=dp[n]
ans=""

while k>0:
    for s in S:
        x=E[s]
        if n-x<0:
            continue
        if dp[n-x]==k-1:
            ans+=str(s)
            k-=1
            n-=x
            break
print(ans)