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

costs = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# 優先度：桁数, [要素(降順)]
dp = [[0, []] for _ in range(N + 1)]
for a in A:
	cost = costs[a]
	for n in range(N):
		if n != 0 and dp[n][0] == 0:
			continue
		ni = n + cost
		if N < ni:
			break
		np = [dp[n][0] + 1, sorted(dp[n][1] + [a], reverse=True)]
		if dp[ni] < np:
			dp[ni] = np

print(*sorted(dp[N][1], reverse=True), sep="") 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 costs = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6] costs [None, 2, 5, 5, 4, 5, 6, 3, 7, 6] None 2 5 5 4 5 6 3 7 6 [0, []] for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [0, []] 0 [] dp = [[0, []] for _ in range(N + 1)] dp [[0, []] for _ in range(N + 1)] for a in A:
	cost = costs[a]
	for n in range(N):
		if n != 0 and dp[n][0] == 0:
			continue
		ni = n + cost
		if N < ni:
			break
		np = [dp[n][0] + 1, sorted(dp[n][1] + [a], reverse=True)]
		if dp[ni] < np:
			dp[ni] = np a A cost = costs[a] cost costs[a] costs a for n in range(N):
		if n != 0 and dp[n][0] == 0:
			continue
		ni = n + cost
		if N < ni:
			break
		np = [dp[n][0] + 1, sorted(dp[n][1] + [a], reverse=True)]
		if dp[ni] < np:
			dp[ni] = np n range(N) range N if n != 0 and dp[n][0] == 0:
			continue
		 n != 0 and dp[n][0] == 0 n != 0 n 0 dp[n][0] == 0 dp[n][0] [n] dp n 0 0 continue ni = n + cost ni n + cost n cost if N < ni:
			break
		 N < ni N ni break np = [dp[n][0] + 1, sorted(dp[n][1] + [a], reverse=True)] np [dp[n][0] + 1, sorted(dp[n][1] + [a], reverse=True)] dp[n][0] + 1 dp[n][0] [n] dp n 0 1 sorted(dp[n][1] + [a], reverse=True) sorted dp[n][1] + [a] dp[n][1] [n] dp n 1 [a] a reverse=True reverse True if dp[ni] < np:
			dp[ni] = np dp[ni] < np dp[ni] dp ni np dp[ni] = np dp[ni] dp ni np print(*sorted(dp[N][1], reverse=True), sep="") print *sorted(dp[N][1], reverse=True) sorted(dp[N][1], reverse=True) sorted dp[N][1] [N] dp N 1 reverse=True reverse True sep="" sep "" dp = [[0, []] for _ in range(N + 1)] [[0, []] for _ in range(N + 1)] dp M = map(int, input().split()) map(int, input().split()) M ni = n + cost n + cost ni N, M = map(int, input().split()) map(int, input().split()) N costs = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6] [None, 2, 5, 5, 4, 5, 6, 3, 7, 6] costs np = [dp[n][0] + 1, sorted(dp[n][1] + [a], reverse=True)] [dp[n][0] + 1, sorted(dp[n][1] + [a], reverse=True)] np A = list(map(int, input().split())) list(map(int, input().split())) A cost = costs[a] costs[a] cost
N, M = map(int, input().split())
A = list(map(int, input().split()))

costs = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# 優先度：桁数, [要素(降順)]
dp = [[0, []] for _ in range(N + 1)]
for a in A:
	cost = costs[a]
	for n in range(N):
		if n != 0 and dp[n][0] == 0:
			continue
		ni = n + cost
		if N < ni:
			break
		np = [dp[n][0] + 1, sorted(dp[n][1] + [a], reverse=True)]
		if dp[ni] < np:
			dp[ni] = np

print(*sorted(dp[N][1], reverse=True), sep="")
