#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	ll n,t,x; cin>>n>>t;
	ll px=-1,ans=0;
	for(ll i=0;i<n;i++){
		cin>>x;
		ans+=t;
		if(px!=-1) ans-=max((ll)0,px-x+t);
		px=x;
	}
	cout<<ans;
}

#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

bool Less(const string& a, const string& b) {
  if (a.size() != b.size()) return a.size() < b.size();
  return a < b;
}

int main() {
  const vector<int> cost = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  in(int, n, m);

  vector<int> a(m);
  rep(i, m) cin >> a[i];

  vector<string> dp(n + 1);
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      int k = i - cost[a[j]];
      if (k < 0 || dp[k] == "" && k != 0) continue;
      string d = char('0' + a[j]) + dp[k];
      if (Less(dp[i], d)) dp[i] = d;
    }
  }
  out(dp[n]);
}
