N, M, *A = map(int, open(0).read().split())

C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5]

dp = [0] * N + [-1] * 9
for i in range(N):
    dp[i + 1] = max(a + 10 * dp[i - C[a]] for a in A)

print(dp[N]) N, M, *A = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split M *A A C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5] C [0, 1, 4, 4, 3, 4, 5, 2, 6, 5] 0 1 4 4 3 4 5 2 6 5 dp = [0] * N + [-1] * 9 dp [0] * N + [-1] * 9 [0] * N [0] 0 N [-1] * 9 [-1] -1 9 for i in range(N):
    dp[i + 1] = max(a + 10 * dp[i - C[a]] for a in A) i range(N) range N dp[i + 1] = max(a + 10 * dp[i - C[a]] for a in A) dp[i + 1] dp i + 1 i 1 max(a + 10 * dp[i - C[a]] for a in A) max a + 10 * dp[i - C[a]] a 10 * dp[i - C[a]] 10 dp[i - C[a]] dp i - C[a] i C[a] C a print(dp[N]) print dp[N] dp N dp = [0] * N + [-1] * 9 [0] * N + [-1] * 9 dp M, *A = map(int, open(0).read().split()) map(int, open(0).read().split()) M C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5] [0, 1, 4, 4, 3, 4, 5, 2, 6, 5] C N, M, *A = map(int, open(0).read().split()) map(int, open(0).read().split()) N
N, M, *A = map(int, open(0).read().split())

C = [0, 1, 4, 4, 3, 4, 5, 2, 6, 5]

dp = [0] * N + [-1] * 9
for i in range(N):
    dp[i + 1] = max(a + 10 * dp[i - C[a]] for a in A)

print(dp[N])
