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