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

int dp[10005];
int M[10] = {0,2,5,5,4,5,6,3,7,6};
int a[10];

int main() {
  int n,m;
  cin >> n >> m;

  for(int i = 0; i < m; i++) cin >> a[i];
  fill(dp,dp+n+1,-1);

  dp[0] = 0;
  
  for(int i = 0; i < n; i++) {
    if(dp[i] == -1) continue;
    for(int j = 0; j < m; j++) {
      dp[M[a[j]] + i] = max(dp[M[a[j]] + i],dp[i] + 1);
    }
  }
  sort(a,a+m,greater<int> ());

  int tmp = n;
  for(int i = 0; i < dp[n]; i++) {
    for(int j = 0; j < m; j++) {
      if(tmp - M[a[j]] < 0) continue;
      if(dp[tmp - M[a[j]]] == dp[tmp] - 1) {
	//	cout << tmp << endl;
	tmp -= M[a[j]];
	cout << a[j];
	break;
      }
    }
  }
  cout << endl;
}
  
