#include<bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e4,INF=1e8;
int dp[MAX_N+1][10];
int N,M,A[9],mat[9]={2,5,5,4,5,6,3,7,6};
int dig;
void dfs(int d){
	if(d==dig)return;
	for(int i=M-1;i>=0;i--){
		if(N>=mat[A[i]-1] && dp[N-mat[A[i]-1]][M]==dig-1-d){
			N-=mat[A[i]-1];
			cout<<A[i];
			dfs(d+1);
			return;
		}
	}
}
int main(){
	cin>>N>>M;
	REP(i,M)cin>>A[i];
	sort(A,A+M);
	REP(i,N){
		dp[i+1][0]=-INF;
	}
	dp[0][0]=0;
	REP(i,M){
		REP(j,N+1){
			dp[j][i+1]=dp[j][i];
			if(j>=mat[A[i]-1]){
				dp[j][i+1]=max(dp[j][i+1],dp[j-mat[A[i]-1]][i+1]+1);
			}
		}
	}
	dig=dp[N][M];
	dfs(0);
	cout<<endl;
}