"use strict";
function Main(input) {
    let lines = input.split("\n");
    let lines1 = lines.shift().split(/\s/).map((v) => v - 0);
    let N = lines1[0];
    let M = lines1[1];
    let a = lines[0].split(/\s/).map((v) => v - 0);

    const u = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6];
    let v = [];
    a.sort((a, b) => b - a);
    for (let m = 0; m < M; m++) {
        v[m] = u[a[m]];
    }
    var ans = [""];
    for (let n = 1; n <= N; n++) {
        for (let m = 0; m < M; m++) {
            const t = n - v[m];
            if (t >= 0 && ans[t] !== undefined) {
                if (ans[n] === undefined) ans[n] = "";
                const l = ans[n].length;
                if (l <= ans[t].length) {
                    ans[n] = ans[t] + a[m];
                }
            }
        }
    }
    ans = ans[N].split("");
    ans.sort((a, b) => b - a);
    console.log(ans.join(""));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
