N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
numk={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[0]+[-1]*(N+1)
for i in range(N):
    for j in A:
        if i+numk[j]<=N:
            dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1)
m=N
ans=[]
while m>0:
    for i in A:
        if m-numk[i]>=0 and dp[m-numk[i]]+1==dp[m]:
            ans.append(str(i))
            m-=numk[i]
            break
print(''.join(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 numk={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} numk {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 dp=[0]+[-1]*(N+1) dp [0]+[-1]*(N+1) [0] 0 [-1]*(N+1) [-1] -1 N+1 N 1 for i in range(N):
    for j in A:
        if i+numk[j]<=N:
            dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1) i range(N) range N for j in A:
        if i+numk[j]<=N:
            dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1) j A if i+numk[j]<=N:
            dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1) i+numk[j]<=N i+numk[j] i numk[j] numk j N dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1) dp[i+numk[j]] dp i+numk[j] i numk[j] numk j max(dp[i+numk[j]],dp[i]+1) max dp[i+numk[j]] dp i+numk[j] i numk[j] numk j dp[i]+1 dp[i] dp i 1 m=N m N ans=[] ans [] while m>0:
    for i in A:
        if m-numk[i]>=0 and dp[m-numk[i]]+1==dp[m]:
            ans.append(str(i))
            m-=numk[i]
            break m>0 m 0 for i in A:
        if m-numk[i]>=0 and dp[m-numk[i]]+1==dp[m]:
            ans.append(str(i))
            m-=numk[i]
            break i A if m-numk[i]>=0 and dp[m-numk[i]]+1==dp[m]:
            ans.append(str(i))
            m-=numk[i]
            break m-numk[i]>=0 and dp[m-numk[i]]+1==dp[m] m-numk[i]>=0 m-numk[i] m numk[i] numk i 0 dp[m-numk[i]]+1==dp[m] dp[m-numk[i]]+1 dp[m-numk[i]] dp m-numk[i] m numk[i] numk i 1 dp[m] dp m ans.append(str(i)) ans.append ans append str(i) str i m-=numk[i] m numk[i] numk i break print(''.join(ans)) print ''.join(ans) ''.join '' join ans A=list(map(int,input().split())) list(map(int,input().split())) A N,M=map(int,input().split()) map(int,input().split()) N m=N N m numk={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} numk M=map(int,input().split()) map(int,input().split()) M ans=[] [] ans dp=[0]+[-1]*(N+1) [0]+[-1]*(N+1) dp m-=numk[i] numk[i] m
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
numk={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[0]+[-1]*(N+1)
for i in range(N):
    for j in A:
        if i+numk[j]<=N:
            dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1)
m=N
ans=[]
while m>0:
    for i in A:
        if m-numk[i]>=0 and dp[m-numk[i]]+1==dp[m]:
            ans.append(str(i))
            m-=numk[i]
            break
print(''.join(ans))