n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=1)
use_list = [2,5,5,4,5,6,3,7,6]

ans = [-1]*(n+1)
ans[0] = 0
for a in A:
	ma = use_list[a-1]
	for i in range(n+1):
		if ans[i] == -1:
			continue
		if i+ma > n:
			break
		ans[i+ma] = max(ans[i+ma],ans[i]*10+a)
print(ans[n]) 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=1) A.sort A sort reverse=1 reverse 1 use_list = [2,5,5,4,5,6,3,7,6] use_list [2,5,5,4,5,6,3,7,6] 2 5 5 4 5 6 3 7 6 ans = [-1]*(n+1) ans [-1]*(n+1) [-1] -1 n+1 n 1 ans[0] = 0 ans[0] ans 0 0 for a in A:
	ma = use_list[a-1]
	for i in range(n+1):
		if ans[i] == -1:
			continue
		if i+ma > n:
			break
		ans[i+ma] = max(ans[i+ma],ans[i]*10+a) a A ma = use_list[a-1] ma use_list[a-1] use_list a-1 a 1 for i in range(n+1):
		if ans[i] == -1:
			continue
		if i+ma > n:
			break
		ans[i+ma] = max(ans[i+ma],ans[i]*10+a) i range(n+1) range n+1 n 1 if ans[i] == -1:
			continue
		 ans[i] == -1 ans[i] ans i -1 continue if i+ma > n:
			break
		 i+ma > n i+ma i ma n break ans[i+ma] = max(ans[i+ma],ans[i]*10+a) ans[i+ma] ans i+ma i ma max(ans[i+ma],ans[i]*10+a) max ans[i+ma] ans i+ma i ma ans[i]*10+a ans[i]*10 ans[i] ans i 10 a print(ans[n]) print ans[n] ans n ans = [-1]*(n+1) [-1]*(n+1) ans ma = use_list[a-1] use_list[a-1] ma A = list(map(int,input().split())) list(map(int,input().split())) A n,m = map(int,input().split()) map(int,input().split()) n use_list = [2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] use_list m = map(int,input().split()) map(int,input().split()) m
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=1)
use_list = [2,5,5,4,5,6,3,7,6]

ans = [-1]*(n+1)
ans[0] = 0
for a in A:
	ma = use_list[a-1]
	for i in range(n+1):
		if ans[i] == -1:
			continue
		if i+ma > n:
			break
		ans[i+ma] = max(ans[i+ma],ans[i]*10+a)
print(ans[n])