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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, m;
    scan(n, m);

    auto a = readln.split.to!(int[]);
    a.sort();

    auto c = [1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6];

    auto dp = new int[][](m + 1, n + 1);
    fillAll(dp, -inf3);
    dp[0][0] = 0;

    foreach (i ; 0 .. m) {
        int ci = c[a[i]];
        foreach (j ; 0 .. n + 1) {
            dp[i + 1][j] = dp[i][j];
            if (j - ci >= 0) {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - ci] + 1);
            }
        }
    }

    debug {
        writefln("%(%s\n%)", dp);
    }

    int mp = m, np = n;
    string ans;

    while (mp > 0 && np > 0) {
        int ci = c[a[mp - 1]];
        if (np - ci < 0) {
            mp--;
            continue;
        }
        if (dp[mp][np] == dp[mp][np - ci] + 1) {
            np -= ci;
            ans ~= ('0' + a[mp - 1]).to!char;
            continue;
        }
        mp--;
    }

    writeln(ans);
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
