#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<int,int> P;
ll mod=pow(10,9)+7;
ll INF=pow(10,18);

int main(){
    int N,M;scanf("%d %d",&N,&M);
    vec A(M);
    for(int i=0;i<M;i++) scanf("%lld",&A[i]);
    sort(A.begin(),A.end(),greater<ll>());
    vec n={0,2,5,5,4,5,6,3,7,6};
    mat dp(N+1,vec(M+1,0));
    //漸化式
    for(int i=0;i<N-1;i++){
        if(i>0 && dp[i][0]==0) continue;
        vec v;
        for(int j=0;j<M;j++){
            if(i+n[A[j]]>N) continue;
            v=dp[i];v[0]++;v[j+1]++;
            int t=dp[i+n[A[j]]][0];
            if(v[0]>t){
                dp[i+n[A[j]]]=v;
            }
            else if(v[0]==t){
                for(int k=1;k<=M;k++){
                    if(v[k]>dp[i+n[A[j]]][k]){
                        dp[i+n[A[j]]]=v;
                        break;
                    }
                    else if(v[k]<dp[i+n[A[j]]][k]){
                        break;
                    }
                }
            }
        }
    }
    string ans;
    for(int i=0;i<M;i++){
        char c=A[i]+'0';
        for(int j=0;j<dp[N][i+1];j++) ans+=c;
    }
    cout<<ans<<endl;
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, m; cin >> n >> m;
    vint change = {0,2,5,5,4,5,6,3,7,6};
    vint a(m);
    rep(i,m) cin >> a[i];
    set<int> st;
    rep(i,m) st.insert(change[a[i]]);
    vint dp(n+1,-1);    
    dp[0] = 0;
    REP(i,n+1) {
        for (auto x : st) {
            if (i-x >= 0 && dp[i-x] != -1) {
                chmax(dp[i],dp[i-x]+1);
            }
        }
    }
    int n_split = dp[n];
    sort(rall(a));
    string ans;
    while (n_split--) {
        rep(i,m) {
            if (n-change[a[i]] < 0) continue;
            if (dp[n-change[a[i]]] == dp[n] - 1) {
                ans += to_string(a[i]);
                n -= change[a[i]];
                break;
            }
        }
    }
    cout << ans << endl;
}