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

dp = [-1 for i in range(N+1)]
dp[0] = 0


for i in range(1,N+1):
    tmp = -1
    for a in A:
        if i-d[a]>=0 and dp[i-d[a]] != -1:
            tmp = max(tmp,dp[i-d[a]]+1)
    dp[i] = tmp


A.sort(reverse=True)
ans = ''
while N>0:
    for a in A:
        if N-d[a]>=0 and dp[N-d[a]] == dp[N]-1:
            ans += str(a)
            N -= d[a]
            break
print(ans)


 d=[0,2,5,5,4,5,6,3,7,6] d [0,2,5,5,4,5,6,3,7,6] 0 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 -1 for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) -1 dp = [-1 for i in range(N+1)] dp [-1 for i in range(N+1)] dp[0] = 0 dp[0] dp 0 0 for i in range(1,N+1):
    tmp = -1
    for a in A:
        if i-d[a]>=0 and dp[i-d[a]] != -1:
            tmp = max(tmp,dp[i-d[a]]+1)
    dp[i] = tmp i range(1,N+1) range 1 N+1 N 1 tmp = -1 tmp -1 for a in A:
        if i-d[a]>=0 and dp[i-d[a]] != -1:
            tmp = max(tmp,dp[i-d[a]]+1)
     a A if i-d[a]>=0 and dp[i-d[a]] != -1:
            tmp = max(tmp,dp[i-d[a]]+1)
     i-d[a]>=0 and dp[i-d[a]] != -1 i-d[a]>=0 i-d[a] i d[a] d a 0 dp[i-d[a]] != -1 dp[i-d[a]] dp i-d[a] i d[a] d a -1 tmp = max(tmp,dp[i-d[a]]+1) tmp max(tmp,dp[i-d[a]]+1) max tmp dp[i-d[a]]+1 dp[i-d[a]] dp i-d[a] i d[a] d a 1 dp[i] = tmp dp[i] dp i tmp A.sort(reverse=True) A.sort A sort reverse=True reverse True ans = '' ans '' while N>0:
    for a in A:
        if N-d[a]>=0 and dp[N-d[a]] == dp[N]-1:
            ans += str(a)
            N -= d[a]
            break N>0 N 0 for a in A:
        if N-d[a]>=0 and dp[N-d[a]] == dp[N]-1:
            ans += str(a)
            N -= d[a]
            break a A if N-d[a]>=0 and dp[N-d[a]] == dp[N]-1:
            ans += str(a)
            N -= d[a]
            break N-d[a]>=0 and dp[N-d[a]] == dp[N]-1 N-d[a]>=0 N-d[a] N d[a] d a 0 dp[N-d[a]] == dp[N]-1 dp[N-d[a]] dp N-d[a] N d[a] d a dp[N]-1 dp[N] dp N 1 ans += str(a) ans str(a) str a N -= d[a] N d[a] d a break print(ans) print ans M=map(int,input().split()) map(int,input().split()) M A=list(map(int,input().split())) list(map(int,input().split())) A N -= d[a] d[a] N N,M=map(int,input().split()) map(int,input().split()) N ans += str(a) str(a) ans d=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] d ans = '' '' ans dp = [-1 for i in range(N+1)] [-1 for i in range(N+1)] dp tmp = -1 -1 tmp tmp = max(tmp,dp[i-d[a]]+1) max(tmp,dp[i-d[a]]+1) tmp
d=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int,input().split())
A=list(map(int,input().split()))

dp = [-1 for i in range(N+1)]
dp[0] = 0


for i in range(1,N+1):
    tmp = -1
    for a in A:
        if i-d[a]>=0 and dp[i-d[a]] != -1:
            tmp = max(tmp,dp[i-d[a]]+1)
    dp[i] = tmp


A.sort(reverse=True)
ans = ''
while N>0:
    for a in A:
        if N-d[a]>=0 and dp[N-d[a]] == dp[N]-1:
            ans += str(a)
            N -= d[a]
            break
print(ans)



