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

dp=[-INF]*(N+1)
dp[0]=0

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

dp=[-INF]*(N+1)
dp[0]=0

for i in range(1,N+1):
    for a in A:
        if i-cost[a]>=0:
            dp[i]=max(dp[i],dp[i-cost[a]]*10+a)
print(dp[N])