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;

string[long] dp;

string solve(long x) {
  if (x in dp) {
    return dp[x];
  }
  if (x < 0) {
    return "-";
  }

  string max = "-";
  foreach (c; cands) {
    auto r = solve(x - assoc[c]) ~ c;
    if (r[0] != '-' && (r.length > max.length || (r.length == max.length && r > max) || 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;
  dp[0] = "";
  writeln(solve(n));
}
