#include<bits/stdc++.h>
using namespace std;
string maxn(string a,string b)
{
    if(a.size()>b.size()) return a;
    if(a.size()<b.size()) return b;
    return a>b?a:b;
}
int mp[11]={0,2,5,5,4,5,6,3,7,6},a[11];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
        cin>>a[i];
    vector<string>dp(10100,"$");
    dp[0]="";
    for(int i=0;i<=n;i++)
	{
        if(dp[i]=="$") 
			continue;
        for(int j=1;j<=m;j++)
            if(i+mp[a[j]]<=n)
                dp[i+mp[a[j]]]=maxn(dp[i+mp[a[j]]],dp[i]+char(a[j]+'0'));
    }
    cout<<dp[n]<<endl;
}