n, m = map(int, input().split())
*a, = map(int, input().split())
sorted_a = sorted(a, reverse=True)

needs = [9,2,5,5,4,5,6,3,7,6]
table = [-1] * (n+10)
table[0] = 0

for i in range(n):
    if table[i] != -1:
        for j in sorted_a:
            table[i + needs[j]] = max(table[i]*10 + j, table[i + needs[j]])

print(table[n]) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m *a, = map(int, input().split()) *a a map(int, input().split()) map int input().split() ().split () input split sorted_a = sorted(a, reverse=True) sorted_a sorted(a, reverse=True) sorted a reverse=True reverse True needs = [9,2,5,5,4,5,6,3,7,6] needs [9,2,5,5,4,5,6,3,7,6] 9 2 5 5 4 5 6 3 7 6 table = [-1] * (n+10) table [-1] * (n+10) [-1] -1 n+10 n 10 table[0] = 0 table[0] table 0 0 for i in range(n):
    if table[i] != -1:
        for j in sorted_a:
            table[i + needs[j]] = max(table[i]*10 + j, table[i + needs[j]]) i range(n) range n if table[i] != -1:
        for j in sorted_a:
            table[i + needs[j]] = max(table[i]*10 + j, table[i + needs[j]]) table[i] != -1 table[i] table i -1 for j in sorted_a:
            table[i + needs[j]] = max(table[i]*10 + j, table[i + needs[j]]) j sorted_a table[i + needs[j]] = max(table[i]*10 + j, table[i + needs[j]]) table[i + needs[j]] table i + needs[j] i needs[j] needs j max(table[i]*10 + j, table[i + needs[j]]) max table[i]*10 + j table[i]*10 table[i] table i 10 j table[i + needs[j]] table i + needs[j] i needs[j] needs j print(table[n]) print table[n] table n sorted_a = sorted(a, reverse=True) sorted(a, reverse=True) sorted_a table = [-1] * (n+10) [-1] * (n+10) table needs = [9,2,5,5,4,5,6,3,7,6] [9,2,5,5,4,5,6,3,7,6] needs n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m
n, m = map(int, input().split())
*a, = map(int, input().split())
sorted_a = sorted(a, reverse=True)

needs = [9,2,5,5,4,5,6,3,7,6]
table = [-1] * (n+10)
table[0] = 0

for i in range(n):
    if table[i] != -1:
        for j in sorted_a:
            table[i + needs[j]] = max(table[i]*10 + j, table[i + needs[j]])

print(table[n])