n, m = map(int, input().split())
a = list(map(int, input().split()))

needs = [10,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 number in sorted(a, reverse = True):
            matchs = needs[number]
            if table[i+matchs] == 0:
                table[i+matchs] = table[i] * 10 + number
            else:
                table[i+matchs] = max(table[i+matchs], table[i] * 10 + number)

print(table[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 needs = [10,2,5,5,4,5,6,3,7,6] needs [10,2,5,5,4,5,6,3,7,6] 10 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 number in sorted(a, reverse = True):
            matchs = needs[number]
            if table[i+matchs] == 0:
                table[i+matchs] = table[i] * 10 + number
            else:
                table[i+matchs] = max(table[i+matchs], table[i] * 10 + number) i range(n) range n if table[i] != -1:
        for number in sorted(a, reverse = True):
            matchs = needs[number]
            if table[i+matchs] == 0:
                table[i+matchs] = table[i] * 10 + number
            else:
                table[i+matchs] = max(table[i+matchs], table[i] * 10 + number) table[i] != -1 table[i] table i -1 for number in sorted(a, reverse = True):
            matchs = needs[number]
            if table[i+matchs] == 0:
                table[i+matchs] = table[i] * 10 + number
            else:
                table[i+matchs] = max(table[i+matchs], table[i] * 10 + number) number sorted(a, reverse = True) sorted a reverse = True reverse True matchs = needs[number] matchs needs[number] needs number if table[i+matchs] == 0:
                table[i+matchs] = table[i] * 10 + number
            else:
                table[i+matchs] = max(table[i+matchs], table[i] * 10 + number) table[i+matchs] == 0 table[i+matchs] table i+matchs i matchs 0 table[i+matchs] = table[i] * 10 + number table[i+matchs] table i+matchs i matchs table[i] * 10 + number table[i] * 10 table[i] table i 10 number table[i+matchs] = max(table[i+matchs], table[i] * 10 + number) table[i+matchs] table i+matchs i matchs max(table[i+matchs], table[i] * 10 + number) max table[i+matchs] table i+matchs i matchs table[i] * 10 + number table[i] * 10 table[i] table i 10 number print(table[n]) print table[n] table n needs = [10,2,5,5,4,5,6,3,7,6] [10,2,5,5,4,5,6,3,7,6] needs matchs = needs[number] needs[number] matchs n, m = map(int, input().split()) map(int, input().split()) n table = [-1] * (n + 10) [-1] * (n + 10) table m = map(int, input().split()) map(int, input().split()) m a = list(map(int, input().split())) list(map(int, input().split())) a
n, m = map(int, input().split())
a = list(map(int, input().split()))

needs = [10,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 number in sorted(a, reverse = True):
            matchs = needs[number]
            if table[i+matchs] == 0:
                table[i+matchs] = table[i] * 10 + number
            else:
                table[i+matchs] = max(table[i+matchs], table[i] * 10 + number)

print(table[n])