I = lambda: map(int, input().split())
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
minf = -float('inf')
n, _ = I()
*A, = sorted(I(), reverse = True)
digs = [0]*(n+1)+[-1]*9
for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d)
ans = []
while n > 0:
    for a in A:
        if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break
print(*ans, sep = '') I = lambda: map(int, input().split()) I lambda: map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] nums [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 minf = -float('inf') minf -float('inf') float('inf') float 'inf' n, _ = I() n I() I _ *A, = sorted(I(), reverse = True) *A A sorted(I(), reverse = True) sorted I() I reverse = True reverse True digs = [0]*(n+1)+[-1]*9 digs [0]*(n+1)+[-1]*9 [0]*(n+1) [0] 0 n+1 n 1 [-1]*9 [-1] -1 9 for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d) i range(1, n+1) range 1 n+1 n 1 d = [] d [] for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
     a A before = i-nums[a] before i-nums[a] i nums[a] nums a d.append(minf if before < 0 else digs[before]+1) d.append d append minf if before < 0 else digs[before]+1 before < 0 before 0 minf digs[before]+1 digs[before] digs before 1 digs[i] = max(d) digs[i] digs i max(d) max d ans = [] ans [] while n > 0:
    for a in A:
        if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break n > 0 n 0 for a in A:
        if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break a A if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break digs[n-nums[a]] == digs[n]-1 digs[n-nums[a]] digs n-nums[a] n nums[a] nums a digs[n]-1 digs[n] digs n 1 ans.append(a) ans.append ans append a n -= nums[a] n nums[a] nums a break print(*ans, sep = '') print *ans ans sep = '' sep '' minf = -float('inf') -float('inf') minf digs = [0]*(n+1)+[-1]*9 [0]*(n+1)+[-1]*9 digs d = [] [] d _ = I() I() _ ans = [] [] ans I = lambda: map(int, input().split()) lambda: map(int, input().split()) I nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] nums n, _ = I() I() n before = i-nums[a] i-nums[a] before n -= nums[a] nums[a] n
I = lambda: map(int, input().split())
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
minf = -float('inf')
n, _ = I()
*A, = sorted(I(), reverse = True)
digs = [0]*(n+1)+[-1]*9
for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d)
ans = []
while n > 0:
    for a in A:
        if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break
print(*ans, sep = '')