N, M = map(int, input().split())
A = list(map(int, input().split()))
m = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
l = min([m[a] for a in A])
dp = [0] * (N + 1)

for i in range(N):
    for a in A:
        if (i > 0) and dp[i] == 0:
            break
        if (i + m[a] <= N):
            dp[i + m[a]] = max(dp[i + m[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 A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] m [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 m[a] for a in A for a in A a A for a in A m[a] m a l = min([m[a] for a in A]) l min([m[a] for a in A]) min [m[a] for a in A] dp = [0] * (N + 1) dp [0] * (N + 1) [0] 0 N + 1 N 1 for i in range(N):
    for a in A:
        if (i > 0) and dp[i] == 0:
            break
        if (i + m[a] <= N):
            dp[i + m[a]] = max(dp[i + m[a]], dp[i] * 10 + a) i range(N) range N for a in A:
        if (i > 0) and dp[i] == 0:
            break
        if (i + m[a] <= N):
            dp[i + m[a]] = max(dp[i + m[a]], dp[i] * 10 + a) a A if (i > 0) and dp[i] == 0:
            break
         (i > 0) and dp[i] == 0 i > 0 i 0 dp[i] == 0 dp[i] dp i 0 break if (i + m[a] <= N):
            dp[i + m[a]] = max(dp[i + m[a]], dp[i] * 10 + a) i + m[a] <= N i + m[a] i m[a] m a N dp[i + m[a]] = max(dp[i + m[a]], dp[i] * 10 + a) dp[i + m[a]] dp i + m[a] i m[a] m a max(dp[i + m[a]], dp[i] * 10 + a) max dp[i + m[a]] dp i + m[a] i m[a] m a dp[i] * 10 + a dp[i] * 10 dp[i] dp i 10 a print(dp[-1]) print dp[-1] dp -1 A = list(map(int, input().split())) list(map(int, input().split())) A m = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] m dp = [0] * (N + 1) [0] * (N + 1) dp l = min([m[a] for a in A]) min([m[a] for a in A]) l M = map(int, input().split()) map(int, input().split()) M N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
A = list(map(int, input().split()))
m = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
l = min([m[a] for a in A])
dp = [0] * (N + 1)

for i in range(N):
    for a in A:
        if (i > 0) and dp[i] == 0:
            break
        if (i + m[a] <= N):
            dp[i + m[a]] = max(dp[i + m[a]], dp[i] * 10 + a)
print(dp[-1])