n,m=map(int,input().split())

A=list(map(int,input().split()))

N=[0,2,5,5,4,5,6,3,7,6]
X=[]
dp=[0]+[-1]*n*9

for i in range(n):
    for j in A:
        if dp[i]>=0:
            dp[i+N[j]]=max(dp[i+N[j]],dp[i]*10+j)

print(dp[n]) 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 N=[0,2,5,5,4,5,6,3,7,6] N [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 X=[] X [] dp=[0]+[-1]*n*9 dp [0]+[-1]*n*9 [0] 0 [-1]*n*9 [-1]*n [-1] -1 n 9 for i in range(n):
    for j in A:
        if dp[i]>=0:
            dp[i+N[j]]=max(dp[i+N[j]],dp[i]*10+j) i range(n) range n for j in A:
        if dp[i]>=0:
            dp[i+N[j]]=max(dp[i+N[j]],dp[i]*10+j) j A if dp[i]>=0:
            dp[i+N[j]]=max(dp[i+N[j]],dp[i]*10+j) dp[i]>=0 dp[i] dp i 0 dp[i+N[j]]=max(dp[i+N[j]],dp[i]*10+j) dp[i+N[j]] dp i+N[j] i N[j] N j max(dp[i+N[j]],dp[i]*10+j) max dp[i+N[j]] dp i+N[j] i N[j] N j dp[i]*10+j dp[i]*10 dp[i] dp i 10 j print(dp[n]) print dp[n] dp n N=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] N A=list(map(int,input().split())) list(map(int,input().split())) A m=map(int,input().split()) map(int,input().split()) m X=[] [] X n,m=map(int,input().split()) map(int,input().split()) n dp=[0]+[-1]*n*9 [0]+[-1]*n*9 dp
n,m=map(int,input().split())

A=list(map(int,input().split()))

N=[0,2,5,5,4,5,6,3,7,6]
X=[]
dp=[0]+[-1]*n*9

for i in range(n):
    for j in A:
        if dp[i]>=0:
            dp[i+N[j]]=max(dp[i+N[j]],dp[i]*10+j)

print(dp[n])