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

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

dp=[0]*(N+1)
cost=[0,2,5,5,4,5,6,3,7,6]
for i in range(1,N+1):
    for a in A:
        if i-cost[a]>=0:
            if dp[i-cost[a]]==0 and i-cost[a]>0:
                continue
            dp[i]=max(dp[i],dp[i-cost[a]]*10+a)
print(dp[-1])