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

enum Num = [2,5,5,4,5,6,3,7,6];

void main() {
    const tmp = readln.split.to!(long[]);
    const N = tmp[0], M = tmp[1];
    const as = readln.split.to!(long[]);

    long cost(long a) {
        return Num[a-1];
    }

    struct Number {
        long[] x;

        int opCmp(Number n) {
            if (x.length < n.x.length) return -1;
            if (x.length > n.x.length) return +1;

            foreach (i; 0..x.length) {
                if (x[i] < n.x[i]) return -1;
                if (x[i] > n.x[i]) return +1;
            }
            return 0;
        }
    }

    struct Result {
        Number n;
        bool valid;
    }

    Result func(long n) {
        if (n < 0) return Result(Number(), false);
        if (n == 0) return Result(Number(), true);
        auto candidates = as
            .map!(a => tuple(a, memoize!func(n-cost(a))))
            .filter!(t => t[1].valid)
            .map!(t => tuple(t[0], t[1].n))
            .map!(t => max(Number(t[0] ~ t[1].x), Number(t[1].x ~ t[0])));

        if (candidates.empty) return Result(Number(), false);

        return Result(candidates.reduce!max, true);
    }

    writeln(func(N).n.x.map!(to!string).join);
}
