#include<bits/stdc++.h>
using namespace std;
///******************************** C o n t a i n e r ********************************///
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
///********************************** M a r c o ***********************************///
#define F first
#define S second
#define mem(a,b) memset(a, b, sizeof(a))
///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///
vector<pair<int,int> > ans;
int siz,n,k,i,dp[10][10004];
vi op; ///op for cost and siz = size of op
int rec(int curi,int curs)
{
if(curi==siz or !curs) return !curs; ///base case
if(dp[curi][curs]!=-1) return dp[curi][curs]; ///memorization
int a=0;
for(int k=curs/op[curi];k>=0;k--){
if(k*op[curi]<=curs) a+=rec(curi+1,curs-k*op[curi]);
else break;
if(a){ans.push_back({op[curi],k}); break;}
}
dp[curi][curs]=a;
return dp[curi][curs];
}
main()
{
vector<string> v(8);
string s;
cin>>n>>k;
int a;
map<int ,int> m;
vi cnt;
mem(dp,-1);
while(k--) cin>>a,m[a]++;
for(i=1;i<10;i++){
if(m[i]){
if(i==1) v[2]="1",op.push_back(2);
else if(i==7) v[3]="7",op.push_back(3);
else if(i==3 or i==5 or i==2){
if(m[1] and m[7]) v[5]="71";
else if(m[5]) v[5]="5";
else if(m[3]) v[5]="3";
else v[5]="2";
op.push_back(5);
}
else if(i==4){
if(m[1]) v[4]="11";
else v[4]="4";
op.push_back(4);
}
else if(i==6 or i==9){
if(m[1]) v[6]="111";
else if(m[7]) v[6]="77";
else if(m[9]) v[6]="9";
else v[6]="6";
op.push_back(6);
}
else{
if(m[7] and m[1]) v[7]="711";
else if(m[7] and m[4]) v[7]="74";
else if(m[5] and m[1]) v[7]="51";
else if(m[3] and m[1]) v[7]="31";
else if(m[2] and m[1]) v[7]="21";
else v[7]="8";
op.push_back(7);
}
}
}
sort(op.begin(),op.end()); siz=op.size();
int x=rec(0,n);
for(auto i:ans){
int y=i.S;
while(y--) s+=v[i.F];
}
sort(s.rbegin(),s.rend());
cout<<s<<endl;
}
///Thank you.
///Brainless_Loco Terminates Here!
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKLy8vKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiogQyBvIG4gdCBhIGkgbiBlIHIgKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovLy8KdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgdmVjdG9yPGludD4gdmk7CnR5cGVkZWYgdmVjdG9yPGxsPiB2bDsKLy8vKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiBNIGEgciBjIG8gKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovLy8KI2RlZmluZSBGIGZpcnN0CiNkZWZpbmUgUyBzZWNvbmQKI2RlZmluZSBtZW0oYSxiKSBtZW1zZXQoYSwgYiwgc2l6ZW9mKGEpKQovLy8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqIEMgbyBkIGUgKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8vLwovLy8tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09LT0tPS09Ly8vCgp2ZWN0b3I8cGFpcjxpbnQsaW50PiA+IGFuczsKaW50IHNpeixuLGssaSxkcFsxMF1bMTAwMDRdOyAKdmkgb3A7ICAgICAgICAgICAgLy8vb3AgZm9yIGNvc3QgYW5kIHNpeiA9IHNpemUgb2Ygb3AKCmludCByZWMoaW50IGN1cmksaW50IGN1cnMpCnsKICAgIGlmKGN1cmk9PXNpeiBvciAhY3VycykgcmV0dXJuICFjdXJzOyAgICAgICAgICAgICAgICAvLy9iYXNlIGNhc2UKICAgIGlmKGRwW2N1cmldW2N1cnNdIT0tMSkgcmV0dXJuIGRwW2N1cmldW2N1cnNdOyAgICAgICAvLy9tZW1vcml6YXRpb24KICAgIGludCBhPTA7CiAgICBmb3IoaW50IGs9Y3Vycy9vcFtjdXJpXTtrPj0wO2stLSl7CiAgICAgICAgaWYoaypvcFtjdXJpXTw9Y3VycykgYSs9cmVjKGN1cmkrMSxjdXJzLWsqb3BbY3VyaV0pOwogICAgICAgIGVsc2UgYnJlYWs7CiAgICAgICAgaWYoYSl7YW5zLnB1c2hfYmFjayh7b3BbY3VyaV0sa30pOyBicmVhazt9CiAgICB9CiAgICBkcFtjdXJpXVtjdXJzXT1hOwogICAgcmV0dXJuIGRwW2N1cmldW2N1cnNdOwp9CgptYWluKCkKewogICAgdmVjdG9yPHN0cmluZz4gdig4KTsKICAgIHN0cmluZyBzOwogICAgY2luPj5uPj5rOwogICAgaW50IGE7CiAgICBtYXA8aW50ICxpbnQ+IG07CiAgICB2aSBjbnQ7CiAgICBtZW0oZHAsLTEpOwogICAgd2hpbGUoay0tKSBjaW4+PmEsbVthXSsrOwogICAgZm9yKGk9MTtpPDEwO2krKyl7CiAgICAgICAgaWYobVtpXSl7CiAgICAgICAgICAgIGlmKGk9PTEpIHZbMl09IjEiLG9wLnB1c2hfYmFjaygyKTsKICAgICAgICAgICAgZWxzZSBpZihpPT03KSB2WzNdPSI3IixvcC5wdXNoX2JhY2soMyk7CiAgICAgICAgICAgIGVsc2UgaWYoaT09MyBvciBpPT01IG9yIGk9PTIpewogICAgICAgICAgICAgICAgaWYobVsxXSBhbmQgbVs3XSkgdls1XT0iNzEiOwogICAgICAgICAgICAgICAgZWxzZSBpZihtWzVdKSB2WzVdPSI1IjsKICAgICAgICAgICAgICAgIGVsc2UgaWYobVszXSkgdls1XT0iMyI7CiAgICAgICAgICAgICAgICBlbHNlIHZbNV09IjIiOwogICAgICAgICAgICAgICAgb3AucHVzaF9iYWNrKDUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYoaT09NCl7CiAgICAgICAgICAgICAgICBpZihtWzFdKSB2WzRdPSIxMSI7CiAgICAgICAgICAgICAgICBlbHNlIHZbNF09IjQiOwogICAgICAgICAgICAgICAgb3AucHVzaF9iYWNrKDQpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYoaT09NiBvciBpPT05KXsKICAgICAgICAgICAgICAgIGlmKG1bMV0pIHZbNl09IjExMSI7CiAgICAgICAgICAgICAgICBlbHNlIGlmKG1bN10pIHZbNl09Ijc3IjsKICAgICAgICAgICAgICAgIGVsc2UgaWYobVs5XSkgdls2XT0iOSI7CiAgICAgICAgICAgICAgICBlbHNlIHZbNl09IjYiOwogICAgICAgICAgICAgICAgb3AucHVzaF9iYWNrKDYpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICBpZihtWzddIGFuZCBtWzFdKSB2WzddPSI3MTEiOwogICAgICAgICAgICAgICAgZWxzZSBpZihtWzddIGFuZCBtWzRdKSB2WzddPSI3NCI7CiAgICAgICAgICAgICAgICBlbHNlIGlmKG1bNV0gYW5kIG1bMV0pIHZbN109IjUxIjsKICAgICAgICAgICAgICAgIGVsc2UgaWYobVszXSBhbmQgbVsxXSkgdls3XT0iMzEiOwogICAgICAgICAgICAgICAgZWxzZSBpZihtWzJdIGFuZCBtWzFdKSB2WzddPSIyMSI7CiAgICAgICAgICAgICAgICBlbHNlIHZbN109IjgiOwogICAgICAgICAgICAgICAgb3AucHVzaF9iYWNrKDcpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgc29ydChvcC5iZWdpbigpLG9wLmVuZCgpKTsgc2l6PW9wLnNpemUoKTsKICAgIGludCB4PXJlYygwLG4pOwogICAgZm9yKGF1dG8gaTphbnMpewogICAgICAgIGludCB5PWkuUzsKICAgICAgICB3aGlsZSh5LS0pIHMrPXZbaS5GXTsKICAgIH0KICAgIHNvcnQocy5yYmVnaW4oKSxzLnJlbmQoKSk7CiAgICBjb3V0PDxzPDxlbmRsOwp9CgoKLy8vVGhhbmsgeW91LgoKCi8vL0JyYWlubGVzc19Mb2NvIFRlcm1pbmF0ZXMgSGVyZSEK