#include <bits/stdc++.h>
using namespace std;
int a[15], memo[15][10010];
int need[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp(int pos, int sisa)
{
	int ret;
	if(sisa==0)
		return 0;
	if (pos==0)
		return -1000000000;
	if (memo[pos][sisa] != -1)
		return memo[pos][sisa];
	ret = dp(pos - 1, sisa);
	if (sisa >= need[a[pos]])
		ret = max(ret, dp(pos,sisa-need[a[pos]])+1);
	memo[pos][sisa] = ret;
	return ret;
}
int main()
{
	int n, m, ans;
	cin>>n>>m;
	for (int i = 1; i <= m; i++)
		cin>>a[i];
	sort(a + 1, a + m + 1);
	memset(memo, -1, sizeof (memo));
	ans=dp(m,n);
	for(int i = 1; i <= ans; i++)
	{
		while (dp(m,n-need[a[m]])!=ans-i)
			m--;
		cout<<a[m];
		n-=need[a[m]];
	}
	cout<<"\n";
	return 0;
}