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

match = [10**18, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# 作れる数字の個数
dp = [-10**18] * (N + 1)
dp[0] = 1

for i in range(N):
    for a in A:
        m = match[a]
        if i + m <= N and dp[i + m] < dp[i] + 1:
            dp[i + m] = dp[i] + 1

ans = []
while N > 0:
    for a in A:
        m = match[a]
        if N - m >= 0 and dp[N - m] + 1 == dp[N]:
            ans.append(a)
            N -= m
            break

ans.sort(reverse=True)

print(''.join(map(str, 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 match = [10**18, 2, 5, 5, 4, 5, 6, 3, 7, 6] match [10**18, 2, 5, 5, 4, 5, 6, 3, 7, 6] 10**18 10 18 2 5 5 4 5 6 3 7 6 dp = [-10**18] * (N + 1) dp [-10**18] * (N + 1) [-10**18] -10**18 -10 18 N + 1 N 1 dp[0] = 1 dp[0] dp 0 1 for i in range(N):
    for a in A:
        m = match[a]
        if i + m <= N and dp[i + m] < dp[i] + 1:
            dp[i + m] = dp[i] + 1 i range(N) range N for a in A:
        m = match[a]
        if i + m <= N and dp[i + m] < dp[i] + 1:
            dp[i + m] = dp[i] + 1 a A m = match[a] m match[a] match a if i + m <= N and dp[i + m] < dp[i] + 1:
            dp[i + m] = dp[i] + 1 i + m <= N and dp[i + m] < dp[i] + 1 i + m <= N i + m i m N dp[i + m] < dp[i] + 1 dp[i + m] dp i + m i m dp[i] + 1 dp[i] dp i 1 dp[i + m] = dp[i] + 1 dp[i + m] dp i + m i m dp[i] + 1 dp[i] dp i 1 ans = [] ans [] while N > 0:
    for a in A:
        m = match[a]
        if N - m >= 0 and dp[N - m] + 1 == dp[N]:
            ans.append(a)
            N -= m
            break N > 0 N 0 for a in A:
        m = match[a]
        if N - m >= 0 and dp[N - m] + 1 == dp[N]:
            ans.append(a)
            N -= m
            break a A m = match[a] m match[a] match a if N - m >= 0 and dp[N - m] + 1 == dp[N]:
            ans.append(a)
            N -= m
            break N - m >= 0 and dp[N - m] + 1 == dp[N] N - m >= 0 N - m N m 0 dp[N - m] + 1 == dp[N] dp[N - m] + 1 dp[N - m] dp N - m N m 1 dp[N] dp N ans.append(a) ans.append ans append a N -= m N m break ans.sort(reverse=True) ans.sort ans sort reverse=True reverse True print(''.join(map(str, ans))) print ''.join(map(str, ans)) ''.join '' join map(str, ans) map str ans m = match[a] match[a] m M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A N -= m m N ans = [] [] ans N, M = map(int, input().split()) map(int, input().split()) N match = [10**18, 2, 5, 5, 4, 5, 6, 3, 7, 6] [10**18, 2, 5, 5, 4, 5, 6, 3, 7, 6] match dp = [-10**18] * (N + 1) [-10**18] * (N + 1) dp m = match[a] match[a] m
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

match = [10**18, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# 作れる数字の個数
dp = [-10**18] * (N + 1)
dp[0] = 1

for i in range(N):
    for a in A:
        m = match[a]
        if i + m <= N and dp[i + m] < dp[i] + 1:
            dp[i + m] = dp[i] + 1

ans = []
while N > 0:
    for a in A:
        m = match[a]
        if N - m >= 0 and dp[N - m] + 1 == dp[N]:
            ans.append(a)
            N -= m
            break

ans.sort(reverse=True)

print(''.join(map(str, ans)))
