import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

const ulong[] cnt = [0,2,5,5,4,5,6,3,7,6];

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = readln.split.map!(to!int).filter!(a => cnt[a] <= N).array;

    auto dp = new string[](N+1);
    dp[] = "0";
    dp[0] = "";

    foreach (i; 0..N) {
        if (dp[i] == "0") continue;
        foreach (j; A) {
            if (i + cnt[j] > N) continue;
            if (dp[i].length + cnt[j] < dp[i+cnt[j]].length) continue;
            string next = dp[i] ~ j.to!string;
            if (next.length == dp[i+cnt[j]].length && next < dp[i+cnt[j]]) continue;
            dp[i+cnt[j]] = next;
        }
    }

    dp[N].writeln;
}
