#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	for (int& i : A) cin >> i;
	vector<string> dp(N + 1);
	vector<int> tmp{ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
	for (int i = 1; i <= N; ++i) {
		for (int& j : A) {
			if (tmp[j] <= i) {
				if (!dp[i - tmp[j]].empty() || tmp[j] == i) dp[i] = max(dp[i - tmp[j]] + to_string(j), dp[i]);
			}
		}
	}
	cout << dp[N];
}