cost=[-1,2,5,5,4,5,6,3,7,6]
N,M=map(int,input().split())
A=list(map(int,input().split()))

dp=[None]*(N+1)
dp[0]=''

for i in range(1,N+1):
    for a in A:
        if i-cost[a]>=0 and dp[i-cost[a]]!=None:
            s=dp[i-cost[a]]+str(a)
            if dp[i]==None or len(dp[i])<len(s):
                dp[i]=s
            elif len(dp[i])>len(s):
                continue
            else:
                dp[i]=max(dp[i],s)
            
            
print(dp[N]) cost=[-1,2,5,5,4,5,6,3,7,6] cost [-1,2,5,5,4,5,6,3,7,6] -1 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=[None]*(N+1) dp [None]*(N+1) [None] None N+1 N 1 dp[0]='' dp[0] dp 0 '' for i in range(1,N+1):
    for a in A:
        if i-cost[a]>=0 and dp[i-cost[a]]!=None:
            s=dp[i-cost[a]]+str(a)
            if dp[i]==None or len(dp[i])<len(s):
                dp[i]=s
            elif len(dp[i])>len(s):
                continue
            else:
                dp[i]=max(dp[i],s)
            
             i range(1,N+1) range 1 N+1 N 1 for a in A:
        if i-cost[a]>=0 and dp[i-cost[a]]!=None:
            s=dp[i-cost[a]]+str(a)
            if dp[i]==None or len(dp[i])<len(s):
                dp[i]=s
            elif len(dp[i])>len(s):
                continue
            else:
                dp[i]=max(dp[i],s)
            
             a A if i-cost[a]>=0 and dp[i-cost[a]]!=None:
            s=dp[i-cost[a]]+str(a)
            if dp[i]==None or len(dp[i])<len(s):
                dp[i]=s
            elif len(dp[i])>len(s):
                continue
            else:
                dp[i]=max(dp[i],s)
            
             i-cost[a]>=0 and dp[i-cost[a]]!=None i-cost[a]>=0 i-cost[a] i cost[a] cost a 0 dp[i-cost[a]]!=None dp[i-cost[a]] dp i-cost[a] i cost[a] cost a None s=dp[i-cost[a]]+str(a) s dp[i-cost[a]]+str(a) dp[i-cost[a]] dp i-cost[a] i cost[a] cost a str(a) str a if dp[i]==None or len(dp[i])<len(s):
                dp[i]=s
            elif len(dp[i])>len(s):
                continue
            else:
                dp[i]=max(dp[i],s)
            
             dp[i]==None or len(dp[i])<len(s) dp[i]==None dp[i] dp i None len(dp[i])<len(s) len(dp[i]) len dp[i] dp i len(s) len s dp[i]=s dp[i] dp i s elif len(dp[i])>len(s):
                continue
             len(dp[i])>len(s) len(dp[i]) len dp[i] dp i len(s) len s continue dp[i]=max(dp[i],s) dp[i] dp i max(dp[i],s) max dp[i] dp i s print(dp[N]) print dp[N] dp N dp=[None]*(N+1) [None]*(N+1) dp s=dp[i-cost[a]]+str(a) dp[i-cost[a]]+str(a) s A=list(map(int,input().split())) list(map(int,input().split())) A N,M=map(int,input().split()) map(int,input().split()) N M=map(int,input().split()) map(int,input().split()) M cost=[-1,2,5,5,4,5,6,3,7,6] [-1,2,5,5,4,5,6,3,7,6] cost
cost=[-1,2,5,5,4,5,6,3,7,6]
N,M=map(int,input().split())
A=list(map(int,input().split()))

dp=[None]*(N+1)
dp[0]=''

for i in range(1,N+1):
    for a in A:
        if i-cost[a]>=0 and dp[i-cost[a]]!=None:
            s=dp[i-cost[a]]+str(a)
            if dp[i]==None or len(dp[i])<len(s):
                dp[i]=s
            elif len(dp[i])>len(s):
                continue
            else:
                dp[i]=max(dp[i],s)
            
            
print(dp[N])