#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

namespace mylib {
struct X {
	vector<int> v;
	X() {
		v.RS(10, 0);
	}
	bool operator<(const X& b) const {
		int resa = 0;
		int resb = 0;
		rep(i, 10) {
			resa += v[i];
			resb += b.v[i];
		}
		if (resa != resb) return resa < resb;
		rrep(i, 10) {
			if (v[i] != b.v[i]) {
				return v[i] < b.v[i];
			}
		}
		return false;
	}
	X operator+(const int b) {
		X res;
		rep(i, 10) {
			res.v[i] = v[i];
		}
		res.v[b]++;
		return res;
	}
};
}
using namespace mylib;

int N, M;
int K[10] = {10000000, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> num;
vector<int> kazu(10, 0);
bool f[10];
vector<X> dp(100000);
vector<pair<int, int>> vp;

void init()
{
	cin >> N >> M;
	rep(i, M) {
		int t;
		cin >> t;
		f[t] = true;
	}
	rep(i, 10) {
		if (!f[i]) K[i] = 10000000;
		else chmax(kazu[K[i]], i);
	}
	rep(i, 10) {
		if (kazu[i]) {
			vp.PB(MP(i, kazu[i]));
		}
	}
}


bool f2[100000];

void solve()
{
	f2[0] = true;
	reps(i, 1, N+1) {
		rep(j, vp.size()) {
			int prev = i-vp[j].first;
			if (prev >= 0) {
				if (f2[prev]) {
					chmax(dp[i], dp[prev] + vp[j].second);
					f2[i] = true;
				}
			}
		}
	}
	rrep(i, 10) {
		rep(j, dp[N].v[i]) {
			cout << i;
		}
	}
	cout << endl;
}





Measured memory_bytes: 12032