#include <iostream>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
#include <bits/stdc++.h>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Grid
ll sx, sy;
ll gx, gy;
ll dx[4] = {-1, +1, +0, +0};
ll dy[4] = {+0, +0, -1, +1};

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template <typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 20 == 19) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}

int ceil(int a, int b) {
    return (a + b - 1) / b;
}

int round(int a, int b) {
    return (a + b / 2) / b;
}

template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}


// Greatest Common Divisor
ll gcd(ll a, ll b)
{
  while (b != 0) {
    a = a % b;
    std::swap(a, b);
  }
  return a;
}

ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}

ll info[10] = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const ll MAX_N = (int)1e4;

// Match N 本使った時の桁数の最大値
//ll dp[MAX_N+1];

int main(int argc, char* argv[])
{
  std::vector<ll> match_num(10, INF);

  ll N, M;
  std::cin >> N >> M;
  std::vector< ll > va(M, 0LL);
  std::map< ll, bool > MM;
  for (ll i = 0; i < M; i++) {
    std::cin >> va[i];
  }
  std::sort(va.begin(), va.end(), std::greater<ll>());
  for (ll i = 0; i < M; i++) {
    if (MM[info[va[i]]] == false) {
      match_num[va[i]] = info[va[i]];
      MM[info[va[i]]] = true;
    }
  }
  //printVec(match_num.begin(), match_num.end());

  std::vector<ll> dp(N + 10, -INF);
  dp[0] = 0LL;
  for (ll i = 0; i <= N; i++) {
    for (ll m = 1; m <= 9; m++) {
      if (match_num[m] == INF) continue;
      dp[i+match_num[m]] = std::max(dp[i+match_num[m]], dp[i] + 1);
    }
  }

  //printVec(dp.begin(), dp.end());
  std::vector<ll> vans(dp[N], 0LL);
  ll idx = 0;
  ll pos = N;
  while (pos > 0) {
    for (ll m = 9; m >= 1; m--) {
      if (match_num[m] == INF) continue;
      if (pos-match_num[m] < 0) continue;
      if (dp[pos] == dp[pos-match_num[m]] + 1) {
	//print("idx", pos-match_num[m], idx, m);
	vans[idx] = m;
	idx++;
	pos -= match_num[m];
	break;
      }
    }
  }

  std::vector<ll>::iterator it;
  for (it = vans.begin(); it != vans.end(); it++) {
    std::cout << *it;
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 384