N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
use=[0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(N+1)
dp[0]=0
for i in range(N+1):
    for k in A:
        if i+use[k]<=N:
            dp[i+use[k]]=max(dp[i]+1,dp[i+use[k]])
ans=""
now=N
for i in range(dp[N]):
    for k in A:
        if now-use[k]>=0:
            if dp[now-use[k]]==dp[now]-1:
                ans+=str(k)
                now-=use[k]
                break
print(ans) 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 A.sort(reverse=True) A.sort A sort reverse=True reverse True use=[0,2,5,5,4,5,6,3,7,6] use [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp=[-1]*(N+1) dp [-1]*(N+1) [-1] -1 N+1 N 1 dp[0]=0 dp[0] dp 0 0 for i in range(N+1):
    for k in A:
        if i+use[k]<=N:
            dp[i+use[k]]=max(dp[i]+1,dp[i+use[k]]) i range(N+1) range N+1 N 1 for k in A:
        if i+use[k]<=N:
            dp[i+use[k]]=max(dp[i]+1,dp[i+use[k]]) k A if i+use[k]<=N:
            dp[i+use[k]]=max(dp[i]+1,dp[i+use[k]]) i+use[k]<=N i+use[k] i use[k] use k N dp[i+use[k]]=max(dp[i]+1,dp[i+use[k]]) dp[i+use[k]] dp i+use[k] i use[k] use k max(dp[i]+1,dp[i+use[k]]) max dp[i]+1 dp[i] dp i 1 dp[i+use[k]] dp i+use[k] i use[k] use k ans="" ans "" now=N now N for i in range(dp[N]):
    for k in A:
        if now-use[k]>=0:
            if dp[now-use[k]]==dp[now]-1:
                ans+=str(k)
                now-=use[k]
                break i range(dp[N]) range dp[N] dp N for k in A:
        if now-use[k]>=0:
            if dp[now-use[k]]==dp[now]-1:
                ans+=str(k)
                now-=use[k]
                break k A if now-use[k]>=0:
            if dp[now-use[k]]==dp[now]-1:
                ans+=str(k)
                now-=use[k]
                break now-use[k]>=0 now-use[k] now use[k] use k 0 if dp[now-use[k]]==dp[now]-1:
                ans+=str(k)
                now-=use[k]
                break dp[now-use[k]]==dp[now]-1 dp[now-use[k]] dp now-use[k] now use[k] use k dp[now]-1 dp[now] dp now 1 ans+=str(k) ans str(k) str k now-=use[k] now use[k] use k break print(ans) print ans now=N N now use=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] use A=list(map(int,input().split())) list(map(int,input().split())) A M=map(int,input().split()) map(int,input().split()) M ans="" "" ans now-=use[k] use[k] now N,M=map(int,input().split()) map(int,input().split()) N dp=[-1]*(N+1) [-1]*(N+1) dp ans+=str(k) str(k) ans
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
use=[0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(N+1)
dp[0]=0
for i in range(N+1):
    for k in A:
        if i+use[k]<=N:
            dp[i+use[k]]=max(dp[i]+1,dp[i+use[k]])
ans=""
now=N
for i in range(dp[N]):
    for k in A:
        if now-use[k]>=0:
            if dp[now-use[k]]==dp[now]-1:
                ans+=str(k)
                now-=use[k]
                break
print(ans)