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

X.sort(reverse=True)
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (N + 1)
dp[0] = 0

for a in X:
    for i in range(N + 1):
        if dp[i] == -1 or i + num[a] > N:
            continue
        dp[i + num[a]] = max(dp[i + num[a]], dp[i] * 10 + a)

print(dp[-1]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M X = list(map(int, input().split())) X list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split X.sort(reverse=True) X.sort X sort reverse=True reverse True num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] num [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 dp = [-1] * (N + 1) dp [-1] * (N + 1) [-1] -1 N + 1 N 1 dp[0] = 0 dp[0] dp 0 0 for a in X:
    for i in range(N + 1):
        if dp[i] == -1 or i + num[a] > N:
            continue
        dp[i + num[a]] = max(dp[i + num[a]], dp[i] * 10 + a) a X for i in range(N + 1):
        if dp[i] == -1 or i + num[a] > N:
            continue
        dp[i + num[a]] = max(dp[i + num[a]], dp[i] * 10 + a) i range(N + 1) range N + 1 N 1 if dp[i] == -1 or i + num[a] > N:
            continue
         dp[i] == -1 or i + num[a] > N dp[i] == -1 dp[i] dp i -1 i + num[a] > N i + num[a] i num[a] num a N continue dp[i + num[a]] = max(dp[i + num[a]], dp[i] * 10 + a) dp[i + num[a]] dp i + num[a] i num[a] num a max(dp[i + num[a]], dp[i] * 10 + a) max dp[i + num[a]] dp i + num[a] i num[a] num a dp[i] * 10 + a dp[i] * 10 dp[i] dp i 10 a print(dp[-1]) print dp[-1] dp -1 num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] num X = list(map(int, input().split())) list(map(int, input().split())) X N, M = map(int, input().split()) map(int, input().split()) N dp = [-1] * (N + 1) [-1] * (N + 1) dp M = map(int, input().split()) map(int, input().split()) M

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

X.sort(reverse=True)
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (N + 1)
dp[0] = 0

for a in X:
    for i in range(N + 1):
        if dp[i] == -1 or i + num[a] > N:
            continue
        dp[i + num[a]] = max(dp[i + num[a]], dp[i] * 10 + a)

print(dp[-1])
