#include <bits/stdc++.h>

#define MAX_N 10000
#define MAX_M 9
typedef long long int ll;

int cost[10] = {MAX_N + 1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[MAX_N + 1];

int main() {
  int n, m, a[MAX_M];

  std::cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    std::cin >> a[i];
  }
  std::sort(a, a + m);

  for(int i = 1; i <= n; ++i) {
    dp[i] = - 10000;
    for(int j = 0; j < m; ++j){
      if(i - cost[a[j]] < 0) {
        continue;
      }
      dp[i] = std::max(dp[i], dp[i - cost[a[j]]] + 1);
    }
  }

  while(n > 0) {
    for(int i = m - 1; m >= 0; --i) {
      if(n >= cost[a[i]] && dp[n] == dp[n - cost[a[i]]] + 1) {
        std::cout << a[i];
        n -= cost[a[i]];
        break;
      }
    }
  }
  std::cout << std::endl;
}