import std.stdio;
import std.string;
import std.algorithm;
import std.array;
import std.conv;
import std.typecons;

long n, m;
long[string] assoc;
string[] cands;

long[long] dp;

long make_dp(long x) {
  if (x in dp) {
    return dp[x];
  }
  if (x < 0) {
    return long.min / 2;
  }

  auto max = long.min / 2;
  foreach (c; cands) {
    auto r = make_dp(x - assoc[c]) + 1;
    if (r > max) {
      max = r;
    }
  }
  dp[x] = max;

  return dp[x];
}

void main() {
  foreach (i, x; [2,5,5,4,5,6,3,7,6]) {
    assoc[(i+1).to!string] = x;
  }

  readf("%d %d\n", &n, &m);
  cands = readln.strip.split(" ").array;
  cands = sort!"a > b"(cands).array;
  dp[0] = 0;
  make_dp(n);

  string ans = "";
  while (n > 0) {
    foreach (c; cands) {
      auto next = n - assoc[c];
      if (next in dp && dp[next] == dp[n]-1) {
        n -= assoc[c];
        ans ~= c;
        break;
      }
    }
  }

  writeln(ans);
}
