#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

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


void chmax(int &a,int b){
  if(a<b)a=b;
}

int main(){
  int n,m;cin>>n>>m;
  map<int,int>a;
  for(int i=0;i<m;++i){
	int x;cin>>x;
	chmax(a[num[x]], x);
  }

  int dp[10010];
  fill(dp,dp+10010,-1.0e+9);
  dp[0]=0;
  for(int i=1;i<=n;++i){
	for(auto it=a.begin();it!=a.end();++it){
	  if(i-it->first>=0)
		chmax(dp[i],dp[i-it->first]+1);
	}
  }
  for(int i=n;i>0;){
	int x=-1;
	for(auto it=a.begin();it!=a.end();++it)
	  if(i-it->first>=0&&dp[i-it->first]==dp[i]-1)
		chmax(x,it->second);
	cout<<x; i-=num[x];
  }
  cout<<endl;
  return 0;
}
