#include <bits/stdc++.h>
using namespace std;

int n, m;
vector<string> dp;
vector<bool> flag;
vector<int> b = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> a(10, -1);

string mymax(const string a, const string b){
	if(a.size() < b.size()) return b;
	if(a.size() > b.size()) return a;
	return max(a, b);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=0; i<m; ++i){
		int t; cin >> t;
		a[b[t]] = max(a[b[t]], t);
	}
	dp.resize(n+1, "");
	flag.resize(n+1, false);
	flag[0] = true;
	for(int i=1; i<=n; ++i)
		for(int j=2; j<=7&&i-j>=0; ++j)
			if(a[j] != -1 && flag[i-j]){
				dp[i] = mymax(dp[i], dp[i-j] + to_string(a[j]));
				flag[i] = true;
			}
	cout << dp[n] << "\n";
}