N , M = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse=True)

match = [2,5,5,4,5,6,3,7,6]

dp = [-float('inf')] * (N + 1)

dp[0] = 0
for i in range(1, N+1) :
    maxDigit = -float('inf')
    for a in A :
        if i - match[a - 1] >= 0 :
            maxDigit = max(maxDigit, dp[i - match[a - 1]] + 1)
    dp[i] = maxDigit

maxDigit = dp[-1]

r = N

for _ in range(maxDigit) :
    for a in A :
        if r - match[a - 1] < 0 or r < 0 :
            continue
        if dp[r - match[a - 1]] == dp[r] - 1 :
            print(a, end='')
            r -= match[a - 1]
            break

print('') 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 A.sort(reverse=True) A.sort A sort reverse=True reverse True match = [2,5,5,4,5,6,3,7,6] match [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 dp = [-float('inf')] * (N + 1) dp [-float('inf')] * (N + 1) [-float('inf')] -float('inf') float('inf') float 'inf' N + 1 N 1 dp[0] = 0 dp[0] dp 0 0 for i in range(1, N+1) :
    maxDigit = -float('inf')
    for a in A :
        if i - match[a - 1] >= 0 :
            maxDigit = max(maxDigit, dp[i - match[a - 1]] + 1)
    dp[i] = maxDigit i range(1, N+1) range 1 N+1 N 1 maxDigit = -float('inf') maxDigit -float('inf') float('inf') float 'inf' for a in A :
        if i - match[a - 1] >= 0 :
            maxDigit = max(maxDigit, dp[i - match[a - 1]] + 1)
     a A if i - match[a - 1] >= 0 :
            maxDigit = max(maxDigit, dp[i - match[a - 1]] + 1)
     i - match[a - 1] >= 0 i - match[a - 1] i match[a - 1] match a - 1 a 1 0 maxDigit = max(maxDigit, dp[i - match[a - 1]] + 1) maxDigit max(maxDigit, dp[i - match[a - 1]] + 1) max maxDigit dp[i - match[a - 1]] + 1 dp[i - match[a - 1]] dp i - match[a - 1] i match[a - 1] match a - 1 a 1 1 dp[i] = maxDigit dp[i] dp i maxDigit maxDigit = dp[-1] maxDigit dp[-1] dp -1 r = N r N for _ in range(maxDigit) :
    for a in A :
        if r - match[a - 1] < 0 or r < 0 :
            continue
        if dp[r - match[a - 1]] == dp[r] - 1 :
            print(a, end='')
            r -= match[a - 1]
            break _ range(maxDigit) range maxDigit for a in A :
        if r - match[a - 1] < 0 or r < 0 :
            continue
        if dp[r - match[a - 1]] == dp[r] - 1 :
            print(a, end='')
            r -= match[a - 1]
            break a A if r - match[a - 1] < 0 or r < 0 :
            continue
         r - match[a - 1] < 0 or r < 0 r - match[a - 1] < 0 r - match[a - 1] r match[a - 1] match a - 1 a 1 0 r < 0 r 0 continue if dp[r - match[a - 1]] == dp[r] - 1 :
            print(a, end='')
            r -= match[a - 1]
            break dp[r - match[a - 1]] == dp[r] - 1 dp[r - match[a - 1]] dp r - match[a - 1] r match[a - 1] match a - 1 a 1 dp[r] - 1 dp[r] dp r 1 print(a, end='') print a end='' end '' r -= match[a - 1] r match[a - 1] match a - 1 a 1 break print('') print '' A = list(map(int,input().split())) list(map(int,input().split())) A match = [2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] match M = map(int,input().split()) map(int,input().split()) M r = N N r maxDigit = -float('inf') -float('inf') maxDigit N , M = map(int,input().split()) map(int,input().split()) N dp = [-float('inf')] * (N + 1) [-float('inf')] * (N + 1) dp maxDigit = max(maxDigit, dp[i - match[a - 1]] + 1) max(maxDigit, dp[i - match[a - 1]] + 1) maxDigit maxDigit = dp[-1] dp[-1] maxDigit r -= match[a - 1] match[a - 1] r
N , M = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse=True)

match = [2,5,5,4,5,6,3,7,6]

dp = [-float('inf')] * (N + 1)

dp[0] = 0
for i in range(1, N+1) :
    maxDigit = -float('inf')
    for a in A :
        if i - match[a - 1] >= 0 :
            maxDigit = max(maxDigit, dp[i - match[a - 1]] + 1)
    dp[i] = maxDigit

maxDigit = dp[-1]

r = N

for _ in range(maxDigit) :
    for a in A :
        if r - match[a - 1] < 0 or r < 0 :
            continue
        if dp[r - match[a - 1]] == dp[r] - 1 :
            print(a, end='')
            r -= match[a - 1]
            break

print('')