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

H = set(T[a-1] for a in A)
H = list(H)
H.sort()

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

for i in range(1,N+1):
    ret = 0
    if i-H[0] < 0:
        continue
    dp[i] = max(dp[i-h] + 1 for h in H if i-h>=0)

ans = ''
j = N
for i in range(1,dp[-1]):
    for a in A:
        if dp[j-T[a-1]] == dp[j] - 1:
            ans += str(a)
            j -= T[a-1]
            break

for a in A:
    if j == T[a-1]:
        ans += str(a)
        j -= T[a-1]
        break

print(ans) 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 T = [2, 5, 5, 4, 5, 6, 3, 7, 6] T [2, 5, 5, 4, 5, 6, 3, 7, 6] 2 5 5 4 5 6 3 7 6 H = set(T[a-1] for a in A) H set(T[a-1] for a in A) set T[a-1] T a-1 a 1 H = list(H) H list(H) list H H.sort() H.sort H sort -1 for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) -1 dp = [-1 for _ in range(N+1)] dp [-1 for _ in range(N+1)] dp[0] = 0 dp[0] dp 0 0 for i in range(1,N+1):
    ret = 0
    if i-H[0] < 0:
        continue
    dp[i] = max(dp[i-h] + 1 for h in H if i-h>=0) i range(1,N+1) range 1 N+1 N 1 ret = 0 ret 0 if i-H[0] < 0:
        continue
     i-H[0] < 0 i-H[0] i H[0] H 0 0 continue dp[i] = max(dp[i-h] + 1 for h in H if i-h>=0) dp[i] dp i max(dp[i-h] + 1 for h in H if i-h>=0) max dp[i-h] + 1 dp[i-h] dp i-h i h 1 ans = '' ans '' j = N j N for i in range(1,dp[-1]):
    for a in A:
        if dp[j-T[a-1]] == dp[j] - 1:
            ans += str(a)
            j -= T[a-1]
            break i range(1,dp[-1]) range 1 dp[-1] dp -1 for a in A:
        if dp[j-T[a-1]] == dp[j] - 1:
            ans += str(a)
            j -= T[a-1]
            break a A if dp[j-T[a-1]] == dp[j] - 1:
            ans += str(a)
            j -= T[a-1]
            break dp[j-T[a-1]] == dp[j] - 1 dp[j-T[a-1]] dp j-T[a-1] j T[a-1] T a-1 a 1 dp[j] - 1 dp[j] dp j 1 ans += str(a) ans str(a) str a j -= T[a-1] j T[a-1] T a-1 a 1 break for a in A:
    if j == T[a-1]:
        ans += str(a)
        j -= T[a-1]
        break a A if j == T[a-1]:
        ans += str(a)
        j -= T[a-1]
        break j == T[a-1] j T[a-1] T a-1 a 1 ans += str(a) ans str(a) str a j -= T[a-1] j T[a-1] T a-1 a 1 break print(ans) print ans N, M = map(int, input().split()) map(int, input().split()) N j = N N j ans = '' '' ans H = set(T[a-1] for a in A) set(T[a-1] for a in A) H j -= T[a-1] T[a-1] j ret = 0 0 ret H = list(H) list(H) H A = list(map(int, input().split())) list(map(int, input().split())) A M = map(int, input().split()) map(int, input().split()) M T = [2, 5, 5, 4, 5, 6, 3, 7, 6] [2, 5, 5, 4, 5, 6, 3, 7, 6] T j -= T[a-1] T[a-1] j ans += str(a) str(a) ans dp = [-1 for _ in range(N+1)] [-1 for _ in range(N+1)] dp ans += str(a) str(a) ans
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
T = [2, 5, 5, 4, 5, 6, 3, 7, 6]

H = set(T[a-1] for a in A)
H = list(H)
H.sort()

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

for i in range(1,N+1):
    ret = 0
    if i-H[0] < 0:
        continue
    dp[i] = max(dp[i-h] + 1 for h in H if i-h>=0)

ans = ''
j = N
for i in range(1,dp[-1]):
    for a in A:
        if dp[j-T[a-1]] == dp[j] - 1:
            ans += str(a)
            j -= T[a-1]
            break

for a in A:
    if j == T[a-1]:
        ans += str(a)
        j -= T[a-1]
        break

print(ans)
