n, m = map(int, input().split())
a = list(map(int, input().split()))
dp = [-1] * (n * 18)
for i in range(n * 9):
    dp[i] = 0
lis = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for i in range(n):
    cnt = -float("inf")
    for j in a:
        cnt = max(cnt, dp[i + 1 - lis[j]] * 10 + j)
    dp[i + 1] = cnt
print(dp[n]) 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 dp = [-1] * (n * 18) dp [-1] * (n * 18) [-1] -1 n * 18 n 18 for i in range(n * 9):
    dp[i] = 0 i range(n * 9) range n * 9 n 9 dp[i] = 0 dp[i] dp i 0 lis = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] lis [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 for i in range(n):
    cnt = -float("inf")
    for j in a:
        cnt = max(cnt, dp[i + 1 - lis[j]] * 10 + j)
    dp[i + 1] = cnt i range(n) range n cnt = -float("inf") cnt -float("inf") float("inf") float "inf" for j in a:
        cnt = max(cnt, dp[i + 1 - lis[j]] * 10 + j)
     j a cnt = max(cnt, dp[i + 1 - lis[j]] * 10 + j) cnt max(cnt, dp[i + 1 - lis[j]] * 10 + j) max cnt dp[i + 1 - lis[j]] * 10 + j dp[i + 1 - lis[j]] * 10 dp[i + 1 - lis[j]] dp i + 1 - lis[j] i + 1 i 1 lis[j] lis j 10 j dp[i + 1] = cnt dp[i + 1] dp i + 1 i 1 cnt print(dp[n]) print dp[n] dp n n, m = map(int, input().split()) map(int, input().split()) n lis = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] lis m = map(int, input().split()) map(int, input().split()) m a = list(map(int, input().split())) list(map(int, input().split())) a dp = [-1] * (n * 18) [-1] * (n * 18) dp cnt = max(cnt, dp[i + 1 - lis[j]] * 10 + j) max(cnt, dp[i + 1 - lis[j]] * 10 + j) cnt cnt = -float("inf") -float("inf") cnt
n, m = map(int, input().split())
a = list(map(int, input().split()))
dp = [-1] * (n * 18)
for i in range(n * 9):
    dp[i] = 0
lis = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for i in range(n):
    cnt = -float("inf")
    for j in a:
        cnt = max(cnt, dp[i + 1 - lis[j]] * 10 + j)
    dp[i + 1] = cnt
print(dp[n])