#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii>
using vec = vector<T>;
const ll INF = numeric_limits<ll>::max(), MOD = 1e9 + 7;
const int INF_i = numeric_limits<int>::max(), MAX = 1e6;
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  vii v(n);
  int prev(0);
  bool check(1);
  for (int i = 0; i < v.size(); i++) {
    cin >> v[i];
    check &= prev <= v[i];
    prev = v[i];
  }
  if (check) {
    cout << (ll(x) * ll(x + 1)) / 2 << '\n';
    return 0;
  }
  int curr0 = 0;
  int min_e(x), max_e(0);
  set<int> s;
  for (int e : v) {
    if (min_e <= e and e <= curr0) continue;
    auto it = s.upper_bound(e);
    if (it != s.end()) {
      min_e = min(min_e, *it);
      if (min_e <= e) {
        curr0 = e;
      } else {
        curr0 = max(curr0, *s.rbegin());
      }
    }
    s.insert(e);
  }
  cerr << min_e << ", " << curr0 << '\n';
  ll res = ll(min_e) * ll(x - curr0 + 1);
  s.clear();
  int curr1 = x;
  for (int i = n - 1; i >= 0; i--) {
    int e(v[i]);
    if (curr1 <= e and e <= max_e) continue;
    auto it = s.lower_bound(e);
    if (it != s.begin()) {
      it--;
      max_e = max(max_e, *it);
      if (e <= max_e) {
        curr1 = e;
      } else {
        curr1 = min(curr1, *s.begin());
      }
    }
    s.insert(e);
  }
  cerr << curr1 << ", " << max_e << '\n';
  res += ll(curr1) * ll(x - max_e + 1);
  res -= ll(min(min_e, curr1)) * ll(x - max(curr0, max_e) + 1);
  cout << res << '\n';
}
