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

A.sort(reverse=True)

cost = [0,2,5,5,4,5,6,3,7,6]

dp = [-1 for _ in range(N + 1)] #dp[i] i本のマッチを使って作れる最大の桁数
dp[0] = 0

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

ans = ''

i = N
for k in range(dp[N]):
    for a in A:
        if i - cost[a] >= 0 and dp[i - cost[a]] != -1 and dp[i - cost[a]] == dp[i] - 1:
            ans += str(a)
            i -= cost[a]
            break

print(ans) 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 cost = [0,2,5,5,4,5,6,3,7,6] cost [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 -1 for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) -1 dp = [-1 for _ in range(N + 1)] dp [-1 for _ in range(N + 1)] dp[0] = 0 dp[0] dp 0 0 for i in range(1, N + 1):
    for a in A:
        if i - cost[a] >= 0:
            dp[i] = max(dp[i], dp[i - cost[a]] + 1) i range(1, N + 1) range 1 N + 1 N 1 for a in A:
        if i - cost[a] >= 0:
            dp[i] = max(dp[i], dp[i - cost[a]] + 1) a A if i - cost[a] >= 0:
            dp[i] = max(dp[i], dp[i - cost[a]] + 1) i - cost[a] >= 0 i - cost[a] i cost[a] cost a 0 dp[i] = max(dp[i], dp[i - cost[a]] + 1) dp[i] dp i max(dp[i], dp[i - cost[a]] + 1) max dp[i] dp i dp[i - cost[a]] + 1 dp[i - cost[a]] dp i - cost[a] i cost[a] cost a 1 ans = '' ans '' i = N i N for k in range(dp[N]):
    for a in A:
        if i - cost[a] >= 0 and dp[i - cost[a]] != -1 and dp[i - cost[a]] == dp[i] - 1:
            ans += str(a)
            i -= cost[a]
            break k range(dp[N]) range dp[N] dp N for a in A:
        if i - cost[a] >= 0 and dp[i - cost[a]] != -1 and dp[i - cost[a]] == dp[i] - 1:
            ans += str(a)
            i -= cost[a]
            break a A if i - cost[a] >= 0 and dp[i - cost[a]] != -1 and dp[i - cost[a]] == dp[i] - 1:
            ans += str(a)
            i -= cost[a]
            break i - cost[a] >= 0 and dp[i - cost[a]] != -1 and dp[i - cost[a]] == dp[i] - 1 i - cost[a] >= 0 and dp[i - cost[a]] != -1 i - cost[a] >= 0 i - cost[a] i cost[a] cost a 0 dp[i - cost[a]] != -1 dp[i - cost[a]] dp i - cost[a] i cost[a] cost a -1 dp[i - cost[a]] == dp[i] - 1 dp[i - cost[a]] dp i - cost[a] i cost[a] cost a dp[i] - 1 dp[i] dp i 1 ans += str(a) ans str(a) str a i -= cost[a] i cost[a] cost a break print(ans) print ans ans = '' '' ans ans += str(a) str(a) ans i -= cost[a] cost[a] i A = list(map(int, input().split())) list(map(int, input().split())) A cost = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] cost dp = [-1 for _ in range(N + 1)] [-1 for _ in range(N + 1)] dp N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M i = N N i
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

cost = [0,2,5,5,4,5,6,3,7,6]

dp = [-1 for _ in range(N + 1)] #dp[i] i本のマッチを使って作れる最大の桁数
dp[0] = 0

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

ans = ''

i = N
for k in range(dp[N]):
    for a in A:
        if i - cost[a] >= 0 and dp[i - cost[a]] != -1 and dp[i - cost[a]] == dp[i] - 1:
            ans += str(a)
            i -= cost[a]
            break

print(ans)