import sys
input = sys.stdin.readline

NUM = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
INF = 10**14

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

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

D = dp[N]
ind = N
ans = ''
for _ in range(D):
    for a in A:
        c = NUM[a]
        if ind - c < 0: continue
        if dp[ind] == dp[ind-c] + 1:
            ind -= c
            ans += str(a)
            break
print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline NUM = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] NUM [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 INF = 10**14 INF 10**14 10 14 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 dp = [-INF]*(N+1) dp [-INF]*(N+1) [-INF] -INF INF N+1 N 1 dp[0] = 0 dp[0] dp 0 0 for i in range(N):
    for a in A:
        c = NUM[a]
        if i + c <= N:
            dp[i+c] = max(dp[i+c], dp[i]+1) i range(N) range N for a in A:
        c = NUM[a]
        if i + c <= N:
            dp[i+c] = max(dp[i+c], dp[i]+1) a A c = NUM[a] c NUM[a] NUM a if i + c <= N:
            dp[i+c] = max(dp[i+c], dp[i]+1) i + c <= N i + c i c N dp[i+c] = max(dp[i+c], dp[i]+1) dp[i+c] dp i+c i c max(dp[i+c], dp[i]+1) max dp[i+c] dp i+c i c dp[i]+1 dp[i] dp i 1 D = dp[N] D dp[N] dp N ind = N ind N ans = '' ans '' for _ in range(D):
    for a in A:
        c = NUM[a]
        if ind - c < 0: continue
        if dp[ind] == dp[ind-c] + 1:
            ind -= c
            ans += str(a)
            break _ range(D) range D for a in A:
        c = NUM[a]
        if ind - c < 0: continue
        if dp[ind] == dp[ind-c] + 1:
            ind -= c
            ans += str(a)
            break a A c = NUM[a] c NUM[a] NUM a if ind - c < 0: continue
         ind - c < 0 ind - c ind c 0 if dp[ind] == dp[ind-c] + 1:
            ind -= c
            ans += str(a)
            break dp[ind] == dp[ind-c] + 1 dp[ind] dp ind dp[ind-c] + 1 dp[ind-c] dp ind-c ind c 1 ind -= c ind c ans += str(a) ans str(a) str a break print(ans) print ans input = sys.stdin.readline sys.stdin.readline input D = dp[N] dp[N] D M = map(int, input().split()) map(int, input().split()) M dp = [-INF]*(N+1) [-INF]*(N+1) dp ans = '' '' ans ind -= c c ind N, M = map(int, input().split()) map(int, input().split()) N c = NUM[a] NUM[a] c NUM = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] NUM INF = 10**14 10**14 INF A = list(map(int, input().split())) list(map(int, input().split())) A c = NUM[a] NUM[a] c ind = N N ind ans += str(a) str(a) ans
import sys
input = sys.stdin.readline

NUM = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
INF = 10**14

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

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

D = dp[N]
ind = N
ans = ''
for _ in range(D):
    for a in A:
        c = NUM[a]
        if ind - c < 0: continue
        if dp[ind] == dp[ind-c] + 1:
            ind -= c
            ans += str(a)
            break
print(ans)