N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
req = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

t = [-1]*(N+1)
t[0] = 0
for a in A:
    q = req[a]
    for i in range(q, N+1):
        t[i] = max(t[i], t[i-q] * 10 + a)
print(t[-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 A.sort(reverse=True) A.sort A sort reverse=True reverse True req = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] req [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 t = [-1]*(N+1) t [-1]*(N+1) [-1] -1 N+1 N 1 t[0] = 0 t[0] t 0 0 for a in A:
    q = req[a]
    for i in range(q, N+1):
        t[i] = max(t[i], t[i-q] * 10 + a) a A q = req[a] q req[a] req a for i in range(q, N+1):
        t[i] = max(t[i], t[i-q] * 10 + a) i range(q, N+1) range q N+1 N 1 t[i] = max(t[i], t[i-q] * 10 + a) t[i] t i max(t[i], t[i-q] * 10 + a) max t[i] t i t[i-q] * 10 + a t[i-q] * 10 t[i-q] t i-q i q 10 a print(t[-1]) print t[-1] t -1 M = map(int, input().split()) map(int, input().split()) M req = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] req q = req[a] req[a] q t = [-1]*(N+1) [-1]*(N+1) t A = list(map(int, input().split())) list(map(int, input().split())) A N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
req = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

t = [-1]*(N+1)
t[0] = 0
for a in A:
    q = req[a]
    for i in range(q, N+1):
        t[i] = max(t[i], t[i-q] * 10 + a)
print(t[-1])
