/*
  Warn - Don't change next line else you will get WA verdict. Online Judge is configured to give WA if next line is not present.
  Author - Aryan Choudhary (@aryanc403)
 
  const short DEBUG { 0 };
  #define debug(x) if (DEBUG) cout << #x << " = " << x << '\n'
*/

#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"
#define PI 3.1415926535897932384626433832795
typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

//const lli [3] ={ 999119999L,1000000007L,1000992299L};
//const lli [3] ={ 97L,101L,103L};
//const lli  = chrono::high_resolution_clock::now().time_since_epoch().count();
clock_t time_p=clock();
void aryanc403()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

class CMP
{
public:
    bool operator()(lli a , lli b) //For min priority_queue .
    {
        return ! ( a <= b );
    }
};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    map<lli,lli> ::iterator jt;
    jt=m.find(x);
    if(jt==m.end())         m.insert(mp(x,cnt));
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    map<lli,lli> ::iterator jt;
    jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}
const lli INF = 0xFFFFFFFFFFFFFFFL;
const lli mod = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r;
    lli m;
    string s;
    vi b;
    map<lli,lli> a[10005];
    lli req[15]={0,2,5,5,4,5,6,3,7,6};
    vi :: iterator it;
    //priority_queue < lli , vector < lli > , CMP > pq;// min priority_queue .

lli find(const map<lli,lli> &m,lli n)
{
    auto it=m.find(n);
    if(it==m.end())
        return 0;
    return it->Y;
}

bool cmp(const map<lli,lli> &a,const map<lli,lli> &b)
// return a<b
{
    lli n=0;
    for(auto x:a)
        n+=x.Y;
    for(auto x:b)
        n-=x.Y;
    if(n!=0)
        return n<0;
    repD(n,9,1)
    {
        if(find(a,n)!=find(b,n))
            return find(a,n)<find(b,n);
    }
    return false;
}

void prt(const map<lli,lli> &a)
{
    lli i,j;
    repD(i,9,1)
    {
        j=find(a,i);
        while(j--)
            cout<<i;
    }
    cout<<endl;
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n>>m;
    fo(i,m)
    {
        cin>>in;
        b.pb(in);
    }
    
    for(lli i=2;i<=n;++i)
    {
        a[i].clear();
        for(auto x:b)
        {
            if(req[x]>i)
                continue;
            if(i!=req[x]&&a[i-req[x]].empty())
                continue;
            
            a[0].clear();
            for(auto y:a[i-req[x]])
                add(a[0],y.X,y.Y);
            add(a[0],x);
            if(cmp(a[i],a[0]))
                a[i].swap(a[0]);
        }
        //cout<<i<<" : ";prt(a[i]);
    }
    prt(a[n]);
}   aryanc403();
    return 0;
}

Measured memory_bytes: 1920