matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

n, m = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort(reverse=True)

dp = [-1 for _ in range(n + 1)]
dp[0] = 0
for a in alist:
    match = matches[a]
    for i in range(n - match + 1):
        if dp[i] == -1: continue
        dp[i + match] = max(dp[i + match], dp[i] * 10 + a)

print(dp[-1]) matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] matches [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m alist = list(map(int, input().split())) alist list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split alist.sort(reverse=True) alist.sort alist sort reverse=True reverse True -1 for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) -1 dp = [-1 for _ in range(n + 1)] dp [-1 for _ in range(n + 1)] dp[0] = 0 dp[0] dp 0 0 for a in alist:
    match = matches[a]
    for i in range(n - match + 1):
        if dp[i] == -1: continue
        dp[i + match] = max(dp[i + match], dp[i] * 10 + a) a alist match = matches[a] match matches[a] matches a for i in range(n - match + 1):
        if dp[i] == -1: continue
        dp[i + match] = max(dp[i + match], dp[i] * 10 + a) i range(n - match + 1) range n - match + 1 n - match n match 1 if dp[i] == -1: continue
         dp[i] == -1 dp[i] dp i -1 dp[i + match] = max(dp[i + match], dp[i] * 10 + a) dp[i + match] dp i + match i match max(dp[i + match], dp[i] * 10 + a) max dp[i + match] dp i + match i match dp[i] * 10 + a dp[i] * 10 dp[i] dp i 10 a print(dp[-1]) print dp[-1] dp -1 n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m alist = list(map(int, input().split())) list(map(int, input().split())) alist match = matches[a] matches[a] match matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] matches dp = [-1 for _ in range(n + 1)] [-1 for _ in range(n + 1)] dp
matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

n, m = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort(reverse=True)

dp = [-1 for _ in range(n + 1)]
dp[0] = 0
for a in alist:
    match = matches[a]
    for i in range(n - match + 1):
        if dp[i] == -1: continue
        dp[i + match] = max(dp[i + match], dp[i] * 10 + a)

print(dp[-1])
