#include <iostream>
#include <algorithm>
using namespace std;

int n, m;
int a[9];
int b[9] = { 2, 5, 5, 4, 5, 6, 3, 7, 6 };
int dp[10001];

int main()
{
	cin >> n >> m;

	dp[0] = 0;
	for (int i = 1; i < 10001; i++)
		dp[i] = -10000;

	for (int i = 0; i < m; i++)
		cin >> a[i];

	sort(a, a + m, greater<int>());

	for (int i = 0; i < m; i++) {
		for (int j = 1; j < n + 1; j++) {
			if (j - b[a[i] - 1] >= 0 && dp[j - b[a[i] - 1]] != -10000)
				dp[j] = max(dp[j], dp[j - b[a[i] - 1]] + 1);
		}
	}

	int k = n;
	while (k > 0) {
		for (int i = 0; i < m; i++) {
			if (k - b[a[i] - 1] >= 0 && dp[k] - dp[k - b[a[i] - 1]] == 1) {
				k -= b[a[i] - 1];
				cout << a[i];
				break;
			}
		}		
	}
	cout << endl;

	return 0;
}