#include <cstdio>
#include <algorithm>

using namespace std;
int v[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int vv[10000 + 5] = {1};
int a[10];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++)
        scanf("%d", &a[i]);
    sort(a + 1, a + 1 + m);
    for (int i = 1; i <= m; i++)
        for (int j = v[a[i]]; j <= n; j++)
            vv[j] = max(vv[j], vv[j - v[a[i]]] + 1);
    while (n) {
        if ((n - v[a[m]] >= 0) && (vv[n] == vv[n - v[a[m]]] + 1)) {
            n -= v[a[m]];
            printf("%d", a[m]);
        } else
            m--;
    }
    return 0;
}