#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <stack>
#include <string>
using namespace std;
int table[10]={0,2,5,5,4,5,6,3,7,6};
int use_ok[10];
int dp[100001];
int N,M;
int main(){
	cin >> N >> M;
	for(int i=1;i<=M;i++){
		int x;
		cin >> x;
		use_ok[x]=1;
	}
	for(int i=0;i<100001;i++)dp[i]=-100000000;
		dp[0]=0;
	for(int i=1;i<=N;i++){
		for(int j=1;j<=9;j++){
			if(use_ok[j] && i-table[j]>=0)dp[i]=max(dp[i],dp[i-table[j]]+1);
		}
	}
	//for(int i=0;i<=N;i++)cout << i << " " << dp[i] << endl;

	int aa=N;
	while(aa!=0){
		for(int i=9;i>=1;i--){
			if(aa-table[i]>=0 && dp[aa-table[i]]==(dp[aa]-1) && use_ok[i] ){
				aa-=table[i];
				cout << i;
				break;
			}
		}
	}
	return 0;
}