a = [2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = list(map(int, input().split()))
A = sorted(set(list(map(int, input().split()))), reverse=True)
B = sorted([a[i-1] for i in A])

dp = [-1] * (N+1)
for b in B:
    if b < N+1:
        dp[b] = 1

for i in range(1, N+1):
    for b in B:
        if i < b:
            break
        else:
            dp[i] = max(dp[i], dp[i-b]+1)
digit = dp[-1]

for n in A:
    x = a[n-1]
    if N-x >= 0:
        while dp[N-x] == digit-1:
            print(n, end='')
            N -= x
            digit -= 1
        if N == x:
            print(n, end='')
            N -= x a = [2, 5, 5, 4, 5, 6, 3, 7, 6] a [2, 5, 5, 4, 5, 6, 3, 7, 6] 2 5 5 4 5 6 3 7 6 N, M = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M A = sorted(set(list(map(int, input().split()))), reverse=True) A sorted(set(list(map(int, input().split()))), reverse=True) sorted set(list(map(int, input().split()))) set list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split reverse=True reverse True a[i-1] for i in A for i in A i A for i in A a[i-1] a i-1 i 1 B = sorted([a[i-1] for i in A]) B sorted([a[i-1] for i in A]) sorted [a[i-1] for i in A] dp = [-1] * (N+1) dp [-1] * (N+1) [-1] -1 N+1 N 1 for b in B:
    if b < N+1:
        dp[b] = 1 b B if b < N+1:
        dp[b] = 1 b < N+1 b N+1 N 1 dp[b] = 1 dp[b] dp b 1 for i in range(1, N+1):
    for b in B:
        if i < b:
            break
        else:
            dp[i] = max(dp[i], dp[i-b]+1) i range(1, N+1) range 1 N+1 N 1 for b in B:
        if i < b:
            break
        else:
            dp[i] = max(dp[i], dp[i-b]+1) b B if i < b:
            break
        else:
            dp[i] = max(dp[i], dp[i-b]+1) i < b i b break dp[i] = max(dp[i], dp[i-b]+1) dp[i] dp i max(dp[i], dp[i-b]+1) max dp[i] dp i dp[i-b]+1 dp[i-b] dp i-b i b 1 digit = dp[-1] digit dp[-1] dp -1 for n in A:
    x = a[n-1]
    if N-x >= 0:
        while dp[N-x] == digit-1:
            print(n, end='')
            N -= x
            digit -= 1
        if N == x:
            print(n, end='')
            N -= x n A x = a[n-1] x a[n-1] a n-1 n 1 if N-x >= 0:
        while dp[N-x] == digit-1:
            print(n, end='')
            N -= x
            digit -= 1
        if N == x:
            print(n, end='')
            N -= x N-x >= 0 N-x N x 0 while dp[N-x] == digit-1:
            print(n, end='')
            N -= x
            digit -= 1
         dp[N-x] == digit-1 dp[N-x] dp N-x N x digit-1 digit 1 print(n, end='') print n end='' end '' N -= x N x digit -= 1 digit 1 if N == x:
            print(n, end='')
            N -= x N == x N x print(n, end='') print n end='' end '' N -= x N x N -= x x N N, M = list(map(int, input().split())) list(map(int, input().split())) N B = sorted([a[i-1] for i in A]) sorted([a[i-1] for i in A]) B x = a[n-1] a[n-1] x dp = [-1] * (N+1) [-1] * (N+1) dp a = [2, 5, 5, 4, 5, 6, 3, 7, 6] [2, 5, 5, 4, 5, 6, 3, 7, 6] a A = sorted(set(list(map(int, input().split()))), reverse=True) sorted(set(list(map(int, input().split()))), reverse=True) A N -= x x N digit -= 1 1 digit M = list(map(int, input().split())) list(map(int, input().split())) M digit = dp[-1] dp[-1] digit
a = [2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = list(map(int, input().split()))
A = sorted(set(list(map(int, input().split()))), reverse=True)
B = sorted([a[i-1] for i in A])

dp = [-1] * (N+1)
for b in B:
    if b < N+1:
        dp[b] = 1

for i in range(1, N+1):
    for b in B:
        if i < b:
            break
        else:
            dp[i] = max(dp[i], dp[i-b]+1)
digit = dp[-1]

for n in A:
    x = a[n-1]
    if N-x >= 0:
        while dp[N-x] == digit-1:
            print(n, end='')
            N -= x
            digit -= 1
        if N == x:
            print(n, end='')
            N -= x