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

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

long solve(long x, long y) {
  if (x == 0) {
    return y;
  } else if (x < 0) {
    return -1;
  }

  long r = -1;
  foreach (c; cands) {
    auto r2 = solve(x - assoc[c], y * 10 + c);
    r = max(r, r2);
  }

  return r;
}



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

  readf("%d %d\n", &n, &m);
  cands = readln.strip.split(" ").map!(x => x.to!long).array;
  auto c1 = sort!((a, b) => assoc[a] < assoc[b])(cands).array;
  auto c2 = sort!"a > b"(cands).array;

  long i = 0;
  string s = "";
  while (n > c2[0] * 2) {
    n -= assoc[c1[i]];
    s ~= c1[i].to!string;
  }
  auto r = solve(n, 0);
  s ~= r.to!(string).dup;
  writeln(sort!"a > b"(s.array).array.to!string);
}
