m = [0,2,5,5,4,5,6,3,7,6]

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(len(A)-1, 0, -1):
    for j in range(i-1, -1, -1):
        if m[A[i]] == m[A[j]]:
            del A[i]
            break

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

for i in range(N):
    if dp[i]==-1: continue
    for j in range(len(A)):
        ind = i + m[A[j]]
        if ind <= N:
            dp[ind] = max(dp[ind], dp[i] * 10 + A[j])

print(dp[-1]) m = [0,2,5,5,4,5,6,3,7,6] m [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 A.sort(reverse=True) A.sort A sort reverse=True reverse True for i in range(len(A)-1, 0, -1):
    for j in range(i-1, -1, -1):
        if m[A[i]] == m[A[j]]:
            del A[i]
            break i range(len(A)-1, 0, -1) range len(A)-1 len(A) len A 1 0 -1 for j in range(i-1, -1, -1):
        if m[A[i]] == m[A[j]]:
            del A[i]
            break j range(i-1, -1, -1) range i-1 i 1 -1 -1 if m[A[i]] == m[A[j]]:
            del A[i]
            break m[A[i]] == m[A[j]] m[A[i]] m A[i] A i m[A[j]] m A[j] A j del A[i] A[i] A i break dp = [-1] * (N+1) dp [-1] * (N+1) [-1] -1 N+1 N 1 dp[0] = 0 dp[0] dp 0 0 for i in range(N):
    if dp[i]==-1: continue
    for j in range(len(A)):
        ind = i + m[A[j]]
        if ind <= N:
            dp[ind] = max(dp[ind], dp[i] * 10 + A[j]) i range(N) range N if dp[i]==-1: continue
     dp[i]==-1 dp[i] dp i -1 for j in range(len(A)):
        ind = i + m[A[j]]
        if ind <= N:
            dp[ind] = max(dp[ind], dp[i] * 10 + A[j]) j range(len(A)) range len(A) len A ind = i + m[A[j]] ind i + m[A[j]] i m[A[j]] m A[j] A j if ind <= N:
            dp[ind] = max(dp[ind], dp[i] * 10 + A[j]) ind <= N ind N dp[ind] = max(dp[ind], dp[i] * 10 + A[j]) dp[ind] dp ind max(dp[ind], dp[i] * 10 + A[j]) max dp[ind] dp ind dp[i] * 10 + A[j] dp[i] * 10 dp[i] dp i 10 A[j] A j print(dp[-1]) print dp[-1] dp -1 m = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] m M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A dp = [-1] * (N+1) [-1] * (N+1) dp N, M = map(int, input().split()) map(int, input().split()) N ind = i + m[A[j]] i + m[A[j]] ind
m = [0,2,5,5,4,5,6,3,7,6]

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(len(A)-1, 0, -1):
    for j in range(i-1, -1, -1):
        if m[A[i]] == m[A[j]]:
            del A[i]
            break

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

for i in range(N):
    if dp[i]==-1: continue
    for j in range(len(A)):
        ind = i + m[A[j]]
        if ind <= N:
            dp[ind] = max(dp[ind], dp[i] * 10 + A[j])

print(dp[-1])
