N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = sorted(list(map(int, input().split())), reverse = True) A sorted(list(map(int, input().split())), reverse = True) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split reverse = True reverse True x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] x [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 0 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) 0 dp = [0 for i in range(N+1)] dp [0 for i in range(N+1)] INF = float('inf') INF float('inf') float 'inf' for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t i range(1, N+1) range 1 N+1 N 1 t = -INF t -INF INF for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
     a A if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
     i >= x[a] i x[a] x a t = max(dp[i-x[a]] + 1, t) t max(dp[i-x[a]] + 1, t) max dp[i-x[a]] + 1 dp[i-x[a]] dp i-x[a] i x[a] x a 1 t dp[i] = t dp[i] dp i t K = N K N k = dp[N] k dp[N] dp N ans = "" ans "" while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break k > 0 k 0 for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break a A xa = x[a] xa x[a] x a if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break K >= xa and k == dp[K-xa] + 1 K >= xa K xa k == dp[K-xa] + 1 k dp[K-xa] + 1 dp[K-xa] dp K-xa K xa 1 ans += str(a) ans str(a) str a K -= xa K xa k -= 1 k 1 break print(ans) print ans A = sorted(list(map(int, input().split())), reverse = True) sorted(list(map(int, input().split())), reverse = True) A ans += str(a) str(a) ans M = map(int, input().split()) map(int, input().split()) M N, M = map(int, input().split()) map(int, input().split()) N t = -INF -INF t K = N N K INF = float('inf') float('inf') INF ans = "" "" ans k -= 1 1 k k = dp[N] dp[N] k x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] x t = max(dp[i-x[a]] + 1, t) max(dp[i-x[a]] + 1, t) t dp = [0 for i in range(N+1)] [0 for i in range(N+1)] dp K -= xa xa K xa = x[a] x[a] xa
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)