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

match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
d = dict()
for e in a:
    d[e] = match[e]

dp = [-1] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
    for k, v in d.items():
        if i - v >= 0 and dp[i-v] != -1:
            dp[i] = max(dp[i], dp[i-v] * 10 + k)

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 match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] match [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 d = dict() d dict() dict for e in a:
    d[e] = match[e] e a d[e] = match[e] d[e] d e match[e] match e dp = [-1] * (n + 1) dp [-1] * (n + 1) [-1] -1 n + 1 n 1 dp[0] = 0 dp[0] dp 0 0 for i in range(1, n + 1):
    for k, v in d.items():
        if i - v >= 0 and dp[i-v] != -1:
            dp[i] = max(dp[i], dp[i-v] * 10 + k) i range(1, n + 1) range 1 n + 1 n 1 for k, v in d.items():
        if i - v >= 0 and dp[i-v] != -1:
            dp[i] = max(dp[i], dp[i-v] * 10 + k) k v d.items() d.items d items if i - v >= 0 and dp[i-v] != -1:
            dp[i] = max(dp[i], dp[i-v] * 10 + k) i - v >= 0 and dp[i-v] != -1 i - v >= 0 i - v i v 0 dp[i-v] != -1 dp[i-v] dp i-v i v -1 dp[i] = max(dp[i], dp[i-v] * 10 + k) dp[i] dp i max(dp[i], dp[i-v] * 10 + k) max dp[i] dp i dp[i-v] * 10 + k dp[i-v] * 10 dp[i-v] dp i-v i v 10 k print(dp[n]) print dp[n] dp n m = map(int, input().split()) map(int, input().split()) m dp = [-1] * (n + 1) [-1] * (n + 1) dp match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] match d = dict() dict() d n, m = map(int, input().split()) map(int, input().split()) n a = list(map(int, input().split())) list(map(int, input().split())) a
n, m = map(int, input().split())
a = list(map(int, input().split()))

match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
d = dict()
for e in a:
    d[e] = match[e]

dp = [-1] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
    for k, v in d.items():
        if i - v >= 0 and dp[i-v] != -1:
            dp[i] = max(dp[i], dp[i-v] * 10 + k)

print(dp[n])
