#include <bits/stdc++.h>
using namespace std;

const int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

void chmax(string& a, string b) {
    if (a.size() < b.size())
        a = b;
    else if (a.size() == b.size() && a < b)
        a = b;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i];
    }

    string dp[11000];
    for (int i = 0; i <= N; i++){
        dp[i] = "-";
    }
    dp[0] = "";

    for (int i = 0; i <= N; i++) {
        if (dp[i] == "-") continue;
        for (auto a : A) {
            chmax(dp[i + num[a]], dp[i] + char(a + '0'));
        }
    }

    cout << dp[N] << endl;
}