#include <bits/stdc++.h>
using namespace std;

//#include <boost/algorithm/string/join.hpp>
//#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision; // mp::log10
using bigint = mp::cpp_int;
#include "boost/multi_array.hpp"
//
//using boost::irange;
//using boost::algorithm::join;
//
// boost::multi_array<int, 3> table;
// table.resize(boost::extents[10][9][8]);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
constexpr int N_MAX=1e4+10;

bigint combineold(int a, bigint x) {
  bigint tmp = x;
  int digit = 0;
  while(tmp>0) {
    tmp /= 10;
    digit++;
  }

  bigint ret(a);
  REP(i, digit) {
    ret *= 10;
  }

  return ret + x;
}

// x^y in O(log N)
bigint pow_r(bigint x, ll y) {
  assert(y>=0);

  bigint ret = 1;
  while (y>0) {
    if (y%2) {
      ret = ret*x;
    }
    x *=x;
    y >>= 1;
  }

  return ret;
}

int get_digit(bigint x) {
  if (x==0) return 0;

  int l = 0;
  int r = N_MAX;
  while (true) {
    int m = (l+r)/2;
    if (l==m) break;

    bigint pm = pow_r(10, m);
    if (pm == x) {
      return m;
    } else if (x >= pm) {
      l = m;
    } else {
      r = m;
    }
  }

  return l+1;
}

bigint combine(int a, bigint x) {
  if (x==0) {
    return a;
  }

  int digit = get_digit(x);
//cerr << "x " << x << " digit " << digit << endl;
  return x + pow_r(10, digit)*a;
}

int compare_digit(const string& a, const string& b) {
  if (a.size() != b.size()) {
    return int(a.size()) - int(b.size());
  }

  return a.compare(b);
}

int main(int argc, char** argv) {
  int N;
  int M;
  cin >> N >> M;
  vi A(M);
  for (auto& a : A) {
    cin >> a;
  }

  map<int, int> toMatches;
  toMatches[1] = 2;
  toMatches[2] = 5;
  toMatches[3] = 5;
  toMatches[4] = 4;
  toMatches[5] = 5;
  toMatches[6] = 6;
  toMatches[7] = 3;
  toMatches[8] = 7;
  toMatches[9] = 6;

  // dp[i] := i本使ってできる最大の整数
  vector<string> dp(N+1);
  dp[0] = "0";

  REP(i, N+1) {
    for (auto a : A) {
      if (i<toMatches[a] || dp[i-toMatches[a]] == "") continue;

      string x = to_string(a) + (dp[i-toMatches[a]] == "0" ? "" : dp[i-toMatches[a]]);
      if (compare_digit(dp[i], x) < 0) {
        dp[i] = x;
      }
    }
//cerr << "i " << i << " " << dp[i] << endl;
  }

  cout << dp[N] << endl;

  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


Measured memory_bytes: 29952