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

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(int n, int[] a) {
    auto costs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6];

    // たとえば、2 と 3 は作るのに 5 本必要だけど、数を大きくしたいので 2 を作ることはない
    int[int] cand;
    foreach (e; a) {
        if (e in cand) cand[e] = min(cand[e], costs[e]);
        else cand[e] = costs[e];
    }

//    writeln(cand);

    auto keys = cand.keys;
    keys.sort!((a, b) => costs[a] < costs[b]);

    auto vals = keys.map!(k => costs[k]).array;
    auto dp = new int[][](cand.keys.length, n + 1);

    for (int i = 0; i < vals.length; i++) {
        // i 行目を i-1 行目で初期化
        if (i > 0) dp[i][] = dp[i-1][];

        int cost = vals[i];
        dp[i][cost] = max(dp[i][cost], 1);
        for (int j = 0; j <= n; j++) {
            if (dp[i][j] && j + cost <= n) {
                if (i == 0) dp[i][j + cost] = max(dp[i][j + cost], dp[i][j] + 1);
                else dp[i][j + cost] = max(dp[i][j + cost], dp[i][j] + 1);
            }
        }
    }

    int[] ans;
    if (true) return;
    keys.sort!"a > b";
    int rest = dp[vals.length - 1][n];
    int total = n;
    foreach (k; keys) {
        if (rest == 0) break;

        for (int i = rest; i > 0; i--) {
            int x = costs[k] * i; // k を i 本作る

            if (total - x >= 0) {
                // 作るとして、残りが整合性あっているか調べる

                if (dp[$-1][total - x] == rest - i) {
                    if (rest - i == 0 && total - x > 0) continue;

                    total -= x;
                    rest -= i;

                    for (int j = 0; j < i; j++) {
                        ans ~= k;
                    }
                    break;
                }
            }
        }

    }
    ans.sort!"a > b";
    writeln(ans.map!(text).join());


}

void main() {
    int n, m; scan(n, m);
    auto a = readints;
    calc(n, a);
}
