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



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

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

dp=[-1 for _ in range(N + 100)]
dp[0] = 0

for i in range(N):
	for m in A:
		need = mnum[m]
		if(dp[i] >= 0):
			dp[i+need] = max(dp[i+need], dp[i] * 10 + m);

print(dp[N]) mnum = [0,2,5,5,4,5,6,3,7,6] mnum [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 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 -1 for _ in range(N + 100) for _ in range(N + 100) _ range(N + 100) range N + 100 N 100 for _ in range(N + 100) -1 dp=[-1 for _ in range(N + 100)] dp [-1 for _ in range(N + 100)] dp[0] = 0 dp[0] dp 0 0 for i in range(N):
	for m in A:
		need = mnum[m]
		if(dp[i] >= 0):
			dp[i+need] = max(dp[i+need], dp[i] * 10 + m); i range(N) range N for m in A:
		need = mnum[m]
		if(dp[i] >= 0):
			dp[i+need] = max(dp[i+need], dp[i] * 10 + m); m A need = mnum[m] need mnum[m] mnum m if(dp[i] >= 0):
			dp[i+need] = max(dp[i+need], dp[i] * 10 + m); dp[i] >= 0 dp[i] dp i 0 dp[i+need] = max(dp[i+need], dp[i] * 10 + m) dp[i+need] dp i+need i need max(dp[i+need], dp[i] * 10 + m) max dp[i+need] dp i+need i need dp[i] * 10 + m dp[i] * 10 dp[i] dp i 10 m print(dp[N]) print dp[N] dp N M = map(int, input().split()) map(int, input().split()) M dp=[-1 for _ in range(N + 100)] [-1 for _ in range(N + 100)] dp N,M = map(int, input().split()) map(int, input().split()) N mnum = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] mnum A = list(map(int, input().split())) list(map(int, input().split())) A need = mnum[m] mnum[m] need

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



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

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

dp=[-1 for _ in range(N + 100)]
dp[0] = 0

for i in range(N):
	for m in A:
		need = mnum[m]
		if(dp[i] >= 0):
			dp[i+need] = max(dp[i+need], dp[i] * 10 + m);

print(dp[N])