#include <bits/stdc++.h>
const int N = 10010;
const int s[10] = {0,2,5,5,4,5,6,3,7,6};
struct Node {int id, cnt;} a[20];
int f[N], n, m;
std::vector<int>v[N];
bool operator < (Node a, Node b) { return a.id > b.id; }
int main() {
	std::cin >> n >> m;
	for(int i = 1; i <= m; ++i) std::cin >> a[i].id, a[i].cnt = s[a[i].id];
	std::sort(a + 1, a + m + 1); std::memset(f, -0x3f, sizeof(f)); f[0] = 0;
	for(int i = 1; i <= n; ++i) 
		for(int j = 1; j <= m; ++j) 
			if(i - a[j].cnt >= 0 && f[i - a[j].cnt] + 1 > f[i]) 
				v[i] = v[i - a[j].cnt], v[i].push_back(a[j].id), f[i] = f[i - a[j].cnt] + 1;
	for(int i = v[n].size() - 1; i >= 0; --i) std::cout << v[n][i];
}