n, m = map(int, input().split())
a = list(map(int, input().split()))
l = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n+1)
dp[0] =  0

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

for i in range(n+1):
    for j in a:
        if i + l[j] < n+1:
            dp[i + l[j]] = max(dp[i + l[j]], dp[i]*10 + j)
print(dp[-1])