import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
A = list(map(int, input().split()))

recipe = [2, 5, 5, 4, 5, 6, 3, 7, 6]
available =[]
dp = [-1] * (N + 1)

for i in range(M):
	available.append((A[i], recipe[A[i] - 1]))
	
available.sort(reverse = True)
dp[0] = 0

for i in range(1, N + 1):
	for j in range(M):
		k = i - available[j][1]
		if k >= 0 and dp[k] >= 0:
			if dp[k] + 1 > dp[i]:
				dp[i] = dp[k] + 1

cost = 0
ans = ''

for i in range(dp[N]):
	for j in range(M):
		if N - cost - available[j][1] >= 0 and dp[N - cost - available[j][1]] == dp[N - cost] - 1:
			cost += available[j][1]
			ans += str(available[j][0])
			break
	
print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline '''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#''' 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 recipe = [2, 5, 5, 4, 5, 6, 3, 7, 6] recipe [2, 5, 5, 4, 5, 6, 3, 7, 6] 2 5 5 4 5 6 3 7 6 available =[] available [] dp = [-1] * (N + 1) dp [-1] * (N + 1) [-1] -1 N + 1 N 1 for i in range(M):
	available.append((A[i], recipe[A[i] - 1]))
	 i range(M) range M available.append((A[i], recipe[A[i] - 1])) available.append available append (A[i], recipe[A[i] - 1]) A[i] A i recipe[A[i] - 1] recipe A[i] - 1 A[i] A i 1 available.sort(reverse = True) available.sort available sort reverse = True reverse True dp[0] = 0 dp[0] dp 0 0 for i in range(1, N + 1):
	for j in range(M):
		k = i - available[j][1]
		if k >= 0 and dp[k] >= 0:
			if dp[k] + 1 > dp[i]:
				dp[i] = dp[k] + 1 i range(1, N + 1) range 1 N + 1 N 1 for j in range(M):
		k = i - available[j][1]
		if k >= 0 and dp[k] >= 0:
			if dp[k] + 1 > dp[i]:
				dp[i] = dp[k] + 1 j range(M) range M k = i - available[j][1] k i - available[j][1] i available[j][1] [j] available j 1 if k >= 0 and dp[k] >= 0:
			if dp[k] + 1 > dp[i]:
				dp[i] = dp[k] + 1 k >= 0 and dp[k] >= 0 k >= 0 k 0 dp[k] >= 0 dp[k] dp k 0 if dp[k] + 1 > dp[i]:
				dp[i] = dp[k] + 1 dp[k] + 1 > dp[i] dp[k] + 1 dp[k] dp k 1 dp[i] dp i dp[i] = dp[k] + 1 dp[i] dp i dp[k] + 1 dp[k] dp k 1 cost = 0 cost 0 ans = '' ans '' for i in range(dp[N]):
	for j in range(M):
		if N - cost - available[j][1] >= 0 and dp[N - cost - available[j][1]] == dp[N - cost] - 1:
			cost += available[j][1]
			ans += str(available[j][0])
			break
	 i range(dp[N]) range dp[N] dp N for j in range(M):
		if N - cost - available[j][1] >= 0 and dp[N - cost - available[j][1]] == dp[N - cost] - 1:
			cost += available[j][1]
			ans += str(available[j][0])
			break
	 j range(M) range M if N - cost - available[j][1] >= 0 and dp[N - cost - available[j][1]] == dp[N - cost] - 1:
			cost += available[j][1]
			ans += str(available[j][0])
			break
	 N - cost - available[j][1] >= 0 and dp[N - cost - available[j][1]] == dp[N - cost] - 1 N - cost - available[j][1] >= 0 N - cost - available[j][1] N - cost N cost available[j][1] [j] available j 1 0 dp[N - cost - available[j][1]] == dp[N - cost] - 1 dp[N - cost - available[j][1]] dp N - cost - available[j][1] N - cost N cost available[j][1] [j] available j 1 dp[N - cost] - 1 dp[N - cost] dp N - cost N cost 1 cost += available[j][1] cost available[j][1] [j] available j 1 ans += str(available[j][0]) ans str(available[j][0]) str available[j][0] [j] available j 0 break print(ans) print ans ans = '' '' ans ans += str(available[j][0]) str(available[j][0]) ans N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M input = sys.stdin.readline sys.stdin.readline input cost += available[j][1] available[j][1] cost k = i - available[j][1] i - available[j][1] k cost = 0 0 cost dp = [-1] * (N + 1) [-1] * (N + 1) dp available =[] [] available A = list(map(int, input().split())) list(map(int, input().split())) A recipe = [2, 5, 5, 4, 5, 6, 3, 7, 6] [2, 5, 5, 4, 5, 6, 3, 7, 6] recipe
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
A = list(map(int, input().split()))

recipe = [2, 5, 5, 4, 5, 6, 3, 7, 6]
available =[]
dp = [-1] * (N + 1)

for i in range(M):
	available.append((A[i], recipe[A[i] - 1]))
	
available.sort(reverse = True)
dp[0] = 0

for i in range(1, N + 1):
	for j in range(M):
		k = i - available[j][1]
		if k >= 0 and dp[k] >= 0:
			if dp[k] + 1 > dp[i]:
				dp[i] = dp[k] + 1

cost = 0
ans = ''

for i in range(dp[N]):
	for j in range(M):
		if N - cost - available[j][1] >= 0 and dp[N - cost - available[j][1]] == dp[N - cost] - 1:
			cost += available[j][1]
			ans += str(available[j][0])
			break
	
print(ans)