#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    int INF = -1e9;
    vector<int> dpk(N + 1, INF), A(M);
    for(int i = 0; i < M; i++) cin >> A[i];
    sort(A.begin(), A.end());
    vector<int> cost(M);
    for(int i = 0; i < M; i++){
        if(A[i] == 1) cost[i] = 2;
        else if(A[i] == 2 || A[i] == 3 || A[i] == 5) cost[i] = 5;
        else if(A[i] == 4) cost[i] = 4;
        else if(A[i] == 6 || A[i] == 9) cost[i] = 6;
        else if(A[i] == 7) cost[i] = 3;
        else cost[i] = 7;
    }
    dpk[0] = 0;
    for(int i = 1; i < N + 1; i++){
        for(int j = 0; j < M; j++){
            if(i - cost[j] >= 0) dpk[i] = max(dpk[i], dpk[i - cost[j]] + 1);
        }
    }
    int keta = dpk[N];
    vector<int> ke(keta);
    int i = 0;
    while(N > 0){
        for(int j = M - 1; j >= 0; j--){
            if(N - cost[j] >= 0 && dpk[N] == dpk[N - cost[j]] + 1){
                ke[i] = A[j];
                i++;
                N -= cost[j];
                break;
            }
        }
    }
    for(int i = 0; i < keta; i++){
        cout << ke[i];
    }
    cout << endl;
}
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

string dp[20000];

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    int cost[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    rep(i, m)cin >> a[i];

    rep(i, n + 100)dp[i] = "-";
    dp[0] = "";

    rep(i, n){
        if(dp[i] == "-")continue;
        for(int now : a){
            if(dp[i + cost[now]].size() == dp[i].size() + 1){
                if(dp[i + cost[now]] < dp[i] + to_string(now))dp[i + cost[now]] = dp[i] + to_string(now);
            }
            else if(dp[i + cost[now]].size() < dp[i].size() + 1)dp[i + cost[now]] = dp[i] + to_string(now);
        }
    }
    cout << dp[n] << endl;
}

