d = {
    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(reverse=True)

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


for a in A:
    for j in range(d[a], N + 1):
        dp[j] = max(dp[j], dp[j - d[a]] + 1)

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

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

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


for a in A:
    for j in range(d[a], N + 1):
        dp[j] = max(dp[j], dp[j - d[a]] + 1)

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

print(ans)
