#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
void changeString(string &t,string p){
    if(t=="0") t=p;
    else if(t.size()<p.size()) t=p;
    else if(t.size()==p.size()){
        if(t<p) t=p;
    }
}
string dp[MAX];
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(m);
    sort(ALL(a));
    REP(i,m)IN(a[i]);
    int num[10]={0,2,5,5,4,5,6,3,7,6};
    REP(i,MAX){
        dp[i]="0";
    }
    dp[0]="";
    REP(i,n+1){
        if(dp[i]=="0")continue;
        REP(j,m){
            changeString(dp[i+num[a[j]]],dp[i]+(char)(a[j]+'0'));
        }
    }
    OUT(dp[n]);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  vector<int> v = {2,5,5,4,5,6,3,7,6};
  
  int n,m;
  cin >> n >> m;
  int use = 0;
  rep(i,m){
    int a;
    cin >> a;--a;
    use |= (1<<a);
  }
//  cout << bitset<9>(use) << endl;
  vector<int> dp(n+1,-INT_MAX/5);
  dp[0] = 0;
  rep(i,n+1){
    for(int j=8;j>=0;j--){
      if((1<<j) & use) {
	int nidx = i + v[j];
	if(nidx<=n){
	  dp[nidx] = max(dp[nidx],dp[i]+1);
	  //	  cout << "i ni dpni " << i << " " << nidx << " " << dp[nidx] << endl;
	}
      }
    }
  }
  int cidx = n;
  while(cidx!=0){
    for(int j=8;j>=0;j--){
      if((1<<j) & use) {
	int nidx = cidx - v[j];
	if(nidx>=0 && dp[nidx] +1 == dp[cidx]){
	  cidx=nidx;
	  cout << j+1;
	  break;
	}
      }
    }
  }
  cout << endl;
  //  cout << dp[n] << endl;

  
  return 0;
    

}
