INF = float('inf')
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
c = [0,2,5,5,4,5,6,3,7,6]

dp = [-INF]*(N+1)
dp[0] = 0
for a in A:
    if c[a] <= N:
        dp[c[a]] = 1

for i in range(N+1):
    for a in A:
        if i-c[a]>=0:
            dp[i] = max(dp[i],dp[i-c[a]]+1)

ans = ''
n = N
for a in A:
    if n-c[a]>=0:
        while dp[n] == dp[n-c[a]]+1:
            n -= c[a]
            ans = ans + str(a)
print(ans) INF = float('inf') INF float('inf') float 'inf' 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 c = [0,2,5,5,4,5,6,3,7,6] c [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp = [-INF]*(N+1) dp [-INF]*(N+1) [-INF] -INF INF N+1 N 1 dp[0] = 0 dp[0] dp 0 0 for a in A:
    if c[a] <= N:
        dp[c[a]] = 1 a A if c[a] <= N:
        dp[c[a]] = 1 c[a] <= N c[a] c a N dp[c[a]] = 1 dp[c[a]] dp c[a] c a 1 for i in range(N+1):
    for a in A:
        if i-c[a]>=0:
            dp[i] = max(dp[i],dp[i-c[a]]+1) i range(N+1) range N+1 N 1 for a in A:
        if i-c[a]>=0:
            dp[i] = max(dp[i],dp[i-c[a]]+1) a A if i-c[a]>=0:
            dp[i] = max(dp[i],dp[i-c[a]]+1) i-c[a]>=0 i-c[a] i c[a] c a 0 dp[i] = max(dp[i],dp[i-c[a]]+1) dp[i] dp i max(dp[i],dp[i-c[a]]+1) max dp[i] dp i dp[i-c[a]]+1 dp[i-c[a]] dp i-c[a] i c[a] c a 1 ans = '' ans '' n = N n N for a in A:
    if n-c[a]>=0:
        while dp[n] == dp[n-c[a]]+1:
            n -= c[a]
            ans = ans + str(a) a A if n-c[a]>=0:
        while dp[n] == dp[n-c[a]]+1:
            n -= c[a]
            ans = ans + str(a) n-c[a]>=0 n-c[a] n c[a] c a 0 while dp[n] == dp[n-c[a]]+1:
            n -= c[a]
            ans = ans + str(a) dp[n] == dp[n-c[a]]+1 dp[n] dp n dp[n-c[a]]+1 dp[n-c[a]] dp n-c[a] n c[a] c a 1 n -= c[a] n c[a] c a ans = ans + str(a) ans ans + str(a) ans str(a) str a print(ans) print ans ans = '' '' ans A = list(map(int,input().split())) list(map(int,input().split())) A M = map(int,input().split()) map(int,input().split()) M N,M = map(int,input().split()) map(int,input().split()) N n -= c[a] c[a] n c = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] c dp = [-INF]*(N+1) [-INF]*(N+1) dp INF = float('inf') float('inf') INF n = N N n ans = ans + str(a) ans + str(a) ans
INF = float('inf')
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
c = [0,2,5,5,4,5,6,3,7,6]

dp = [-INF]*(N+1)
dp[0] = 0
for a in A:
    if c[a] <= N:
        dp[c[a]] = 1

for i in range(N+1):
    for a in A:
        if i-c[a]>=0:
            dp[i] = max(dp[i],dp[i-c[a]]+1)

ans = ''
n = N
for a in A:
    if n-c[a]>=0:
        while dp[n] == dp[n-c[a]]+1:
            n -= c[a]
            ans = ans + str(a)
print(ans)