match = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

# 桁数を決めたい、最大を求めたいので前からDP
# dp[n]: n本のマッチでできる最大の桁？
inf = 10**18
dp = [-1] * (N + 10)
dp[0] = 0
for i in range(N):
    if dp[i] == -1:
        continue
    for a in A:
        dp[i + match[a]] = max(dp[i + match[a]], dp[i] + 1)

digit = dp[N]
pos = N
ans = ""
while pos > 0:
    for a in A[::-1]:
        if dp[pos - match[a]] == digit - 1:
            ans += str(a)
            pos -= match[a]
            digit -= 1
            break

print(ans) match = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} match {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 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() A.sort A sort inf = 10**18 inf 10**18 10 18 dp = [-1] * (N + 10) dp [-1] * (N + 10) [-1] -1 N + 10 N 10 dp[0] = 0 dp[0] dp 0 0 for i in range(N):
    if dp[i] == -1:
        continue
    for a in A:
        dp[i + match[a]] = max(dp[i + match[a]], dp[i] + 1) i range(N) range N if dp[i] == -1:
        continue
     dp[i] == -1 dp[i] dp i -1 continue for a in A:
        dp[i + match[a]] = max(dp[i + match[a]], dp[i] + 1) a A dp[i + match[a]] = max(dp[i + match[a]], dp[i] + 1) dp[i + match[a]] dp i + match[a] i match[a] match a max(dp[i + match[a]], dp[i] + 1) max dp[i + match[a]] dp i + match[a] i match[a] match a dp[i] + 1 dp[i] dp i 1 digit = dp[N] digit dp[N] dp N pos = N pos N ans = "" ans "" while pos > 0:
    for a in A[::-1]:
        if dp[pos - match[a]] == digit - 1:
            ans += str(a)
            pos -= match[a]
            digit -= 1
            break pos > 0 pos 0 for a in A[::-1]:
        if dp[pos - match[a]] == digit - 1:
            ans += str(a)
            pos -= match[a]
            digit -= 1
            break a A[::-1] A ::-1 -1 if dp[pos - match[a]] == digit - 1:
            ans += str(a)
            pos -= match[a]
            digit -= 1
            break dp[pos - match[a]] == digit - 1 dp[pos - match[a]] dp pos - match[a] pos match[a] match a digit - 1 digit 1 ans += str(a) ans str(a) str a pos -= match[a] pos match[a] match a digit -= 1 digit 1 break print(ans) print ans pos -= match[a] match[a] pos N, M = map(int, input().split()) map(int, input().split()) N pos = N N pos digit -= 1 1 digit M = map(int, input().split()) map(int, input().split()) M inf = 10**18 10**18 inf match = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
} match ans = "" "" ans ans += str(a) str(a) ans digit = dp[N] dp[N] digit dp = [-1] * (N + 10) [-1] * (N + 10) dp A = list(map(int, input().split())) list(map(int, input().split())) A
match = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

# 桁数を決めたい、最大を求めたいので前からDP
# dp[n]: n本のマッチでできる最大の桁？
inf = 10**18
dp = [-1] * (N + 10)
dp[0] = 0
for i in range(N):
    if dp[i] == -1:
        continue
    for a in A:
        dp[i + match[a]] = max(dp[i + match[a]], dp[i] + 1)

digit = dp[N]
pos = N
ans = ""
while pos > 0:
    for a in A[::-1]:
        if dp[pos - match[a]] == digit - 1:
            ans += str(a)
            pos -= match[a]
            digit -= 1
            break

print(ans)
