n, m = map(int, input().split())
a = list(map(int, input().split()))
d = [10**5, 2,5,5,4,5,6,3,7,6]
dp = [(0, 0)] * (n + 1)
for i in range(n):
    if i > 0 and dp[i][0] == 0:
        continue
    k, _ = dp[i]
    for ai in a:
        if i + d[ai] <= n:
            dp[i+d[ai]] = max(dp[i+d[ai]], (k+1, ai))
ans = []
i = n
for _ in range(dp[n][0]):
    ans.append(str(dp[i][1]))
    i -= d[dp[i][1]]
print(''.join(ans)) 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 d = [10**5, 2,5,5,4,5,6,3,7,6] d [10**5, 2,5,5,4,5,6,3,7,6] 10**5 10 5 2 5 5 4 5 6 3 7 6 dp = [(0, 0)] * (n + 1) dp [(0, 0)] * (n + 1) [(0, 0)] (0, 0) 0 0 n + 1 n 1 for i in range(n):
    if i > 0 and dp[i][0] == 0:
        continue
    k, _ = dp[i]
    for ai in a:
        if i + d[ai] <= n:
            dp[i+d[ai]] = max(dp[i+d[ai]], (k+1, ai)) i range(n) range n if i > 0 and dp[i][0] == 0:
        continue
     i > 0 and dp[i][0] == 0 i > 0 i 0 dp[i][0] == 0 dp[i][0] [i] dp i 0 0 continue k, _ = dp[i] k dp[i] dp i _ for ai in a:
        if i + d[ai] <= n:
            dp[i+d[ai]] = max(dp[i+d[ai]], (k+1, ai)) ai a if i + d[ai] <= n:
            dp[i+d[ai]] = max(dp[i+d[ai]], (k+1, ai)) i + d[ai] <= n i + d[ai] i d[ai] d ai n dp[i+d[ai]] = max(dp[i+d[ai]], (k+1, ai)) dp[i+d[ai]] dp i+d[ai] i d[ai] d ai max(dp[i+d[ai]], (k+1, ai)) max dp[i+d[ai]] dp i+d[ai] i d[ai] d ai (k+1, ai) k+1 k 1 ai ans = [] ans [] i = n i n for _ in range(dp[n][0]):
    ans.append(str(dp[i][1]))
    i -= d[dp[i][1]] _ range(dp[n][0]) range dp[n][0] [n] dp n 0 ans.append(str(dp[i][1])) ans.append ans append str(dp[i][1]) str dp[i][1] [i] dp i 1 i -= d[dp[i][1]] i d[dp[i][1]] d dp[i][1] [i] dp i 1 print(''.join(ans)) print ''.join(ans) ''.join '' join ans _ = dp[i] dp[i] _ dp = [(0, 0)] * (n + 1) [(0, 0)] * (n + 1) dp n, m = map(int, input().split()) map(int, input().split()) n d = [10**5, 2,5,5,4,5,6,3,7,6] [10**5, 2,5,5,4,5,6,3,7,6] d ans = [] [] ans k, _ = dp[i] dp[i] k a = list(map(int, input().split())) list(map(int, input().split())) a i -= d[dp[i][1]] d[dp[i][1]] i i = n n i m = map(int, input().split()) map(int, input().split()) m
n, m = map(int, input().split())
a = list(map(int, input().split()))
d = [10**5, 2,5,5,4,5,6,3,7,6]
dp = [(0, 0)] * (n + 1)
for i in range(n):
    if i > 0 and dp[i][0] == 0:
        continue
    k, _ = dp[i]
    for ai in a:
        if i + d[ai] <= n:
            dp[i+d[ai]] = max(dp[i+d[ai]], (k+1, ai))
ans = []
i = n
for _ in range(dp[n][0]):
    ans.append(str(dp[i][1]))
    i -= d[dp[i][1]]
print(''.join(ans))
