n, m = map(int, input().split())
a = list(map(int , input().split()))
t = [2,5,5,4,5,6,3,7,6]
cost = {ai: t[ai-1] for ai in a}

dp = [0] + [-1] * n

for i in range(1, n+1):
    dpi = -1
    for ai, ci in cost.items():
        if i - ci >= 0 and dp[i-ci] >= 0:
            dpi = max(dp[i-ci] * 10 + ai, dpi)
    dp[i] = dpi
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 t = [2,5,5,4,5,6,3,7,6] t [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 ai: t[ai-1] for ai in a for ai in a ai a for ai in a ai t[ai-1] t ai-1 ai 1 cost = {ai: t[ai-1] for ai in a} cost {ai: t[ai-1] for ai in a} dp = [0] + [-1] * n dp [0] + [-1] * n [0] 0 [-1] * n [-1] -1 n for i in range(1, n+1):
    dpi = -1
    for ai, ci in cost.items():
        if i - ci >= 0 and dp[i-ci] >= 0:
            dpi = max(dp[i-ci] * 10 + ai, dpi)
    dp[i] = dpi i range(1, n+1) range 1 n+1 n 1 dpi = -1 dpi -1 for ai, ci in cost.items():
        if i - ci >= 0 and dp[i-ci] >= 0:
            dpi = max(dp[i-ci] * 10 + ai, dpi)
     ai ci cost.items() cost.items cost items if i - ci >= 0 and dp[i-ci] >= 0:
            dpi = max(dp[i-ci] * 10 + ai, dpi)
     i - ci >= 0 and dp[i-ci] >= 0 i - ci >= 0 i - ci i ci 0 dp[i-ci] >= 0 dp[i-ci] dp i-ci i ci 0 dpi = max(dp[i-ci] * 10 + ai, dpi) dpi max(dp[i-ci] * 10 + ai, dpi) max dp[i-ci] * 10 + ai dp[i-ci] * 10 dp[i-ci] dp i-ci i ci 10 ai dpi dp[i] = dpi dp[i] dp i dpi print(dp[n]) print dp[n] dp n t = [2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] t dp = [0] + [-1] * n [0] + [-1] * n dp dpi = max(dp[i-ci] * 10 + ai, dpi) max(dp[i-ci] * 10 + ai, dpi) dpi cost = {ai: t[ai-1] for ai in a} {ai: t[ai-1] for ai in a} cost a = list(map(int , input().split())) list(map(int , input().split())) a n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m dpi = -1 -1 dpi
n, m = map(int, input().split())
a = list(map(int , input().split()))
t = [2,5,5,4,5,6,3,7,6]
cost = {ai: t[ai-1] for ai in a}

dp = [0] + [-1] * n

for i in range(1, n+1):
    dpi = -1
    for ai, ci in cost.items():
        if i - ci >= 0 and dp[i-ci] >= 0:
            dpi = max(dp[i-ci] * 10 + ai, dpi)
    dp[i] = dpi
print(dp[n])
