N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[2,5,5,4,5,6,3,7,6]


dp=[0]*(N+10)
for j in range(M):
    need=B[A[j]-1]
    dp[need]=max(dp[need],A[j])

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


dp=[0]*(N+10)
for j in range(M):
    need=B[A[j]-1]
    dp[need]=max(dp[need],A[j])

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

