function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
	let N = parseInt(input[0][0], 10);
	let M = parseInt(input[0][1], 10);
	let A = input[1].map(e => parseInt(e, 10));
	let v = [-1,2,5,5,4,5,6,3,7,6];
	let priority = [[1],[7],[4],[5,3,2],[9,6],[8]];	
	let forUse = [];
	for (let x of priority){
		for (let y of x){
			if(A.indexOf(y) !== -1){
				forUse.push([y, v[y]]);
				break;
			}
		}	
	}
	// console.log(forUse);
	eachCount = Array.from({length: forUse.length}, () => 0);
	maxLength = 0;
	candidate = [];
	endPoint = 0;
	recurrent(forUse, 0, N);
	let ans = 0;
	let ary2 = [[0, 0]];
	for (x of candidate){
		let ary = [];
		for (let i = 0; i < x.length; i++){
			if (x[i] === 0) continue;
			ary.push([forUse[i][0], x[i]]);
		}
		ary.sort((a, b) => b[0] - a[0]);
		let flag;
		for (let i = 0; i < ary.length; i++){
			if (ary[0][0] === ary2[0][0] && ary[0][1] === ary2[0][1]) continue;
			if (ary[0][0] > ary2[0][0]) {
				flag = true;
				break;
			}
			if (ary[0][0] < ary2[0][0]) {
				flag = false;
				break;
			}
			if (ary[0][1] > ary2[0][1]) {
				flag = true;
				break;
			}
			if (ary[0][1] < ary2[0][1]) {
				flag = false;
				break;
			}
		}
		if (flag){
			ary2 = [];
			for (let x of ary){
				ary2.push(x.slice());
			}
		}

		// console.log(ary2);
	}
	let v_ans = [];
	for (let x of ary2){
		for (let i = 0; i < x[1]; i++){
			v_ans.push(x[0]);
		}
	}
	console.log(v_ans.join(""));


}

function recurrent(forUse, startPoint, remain){
	// console.log("start", startPoint, remain, eachCount);
	eachCount[startPoint] = Math.floor(remain / forUse[startPoint][1]);
	remain %= forUse[startPoint][1];
	// console.log("er", eachCount, remain);
	if (remain === 0) {
		let tmp = 0;
		for(let i = 0; i <= startPoint; i++){
			tmp += eachCount[i];
		}
		if (tmp > maxLength){
			maxLength = tmp;
			let v2 = eachCount.slice();
			v2.length = startPoint + 1;
			candidate = [v2];
		} else if (tmp === maxLength){
			let v2 = eachCount.slice();
			v2.length = startPoint + 1;
			candidate.push(v2);
		}
		// console.log("OK→", eachCount); 
		eachCount[startPoint] = 0;
		
		return;
	} else {
		for (let i = eachCount[startPoint]; i >= 0; i--){
			if ((startPoint + 1) > (forUse.length - 1)) return;
			recurrent(forUse, startPoint + 1, remain);
			remain += forUse[startPoint][1];
			eachCount[startPoint] --;
			if (startPoint === 0 && eachCount[0] + (remain / forUse[1][1] )< maxLength) return;
		}
	}
	eachCount[startPoint] = 0;

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));