#include <bits/stdc++.h>
using namespace std;
vector<long long> cnt[1000010];
vector<bool> okay(1000010, false);
vector<bool> rev(1000010 + 5, false);
vector<long long> maxx(1000010, 0);
vector<long long> minn(1000010, 100000000000000);
void debug(long long mx) {
  for (long long i = 1; i <= mx; i++) {
    cout << okay[i] << " ";
  }
  cout << "\n";
  for (long long i = 1; i <= mx; i++) {
    cout << rev[i] << " ";
  }
  cout << "\n";
  for (long long i = 1; i <= mx; i++) {
    cout << maxx[i] << " ";
  }
  cout << "\n";
  for (long long i = 1; i <= mx; i++) {
    cout << minn[i] << " ";
  }
  cout << "\n\n\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, x;
  cin >> n >> x;
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    cnt[k].push_back(i);
  }
  okay[0] = true;
  long long mx = -1;
  bool found = false;
  for (long long i = 1; i < 1000010; i++) {
    if (cnt[i].size() == 0) {
      if (!found) okay[i] = true;
      maxx[i] = maxx[i - 1];
      continue;
    } else {
      long long f = cnt[i][0];
      if (f > mx and !found) {
        okay[i] = true;
      } else {
        if (!found) {
          found = true;
          okay[i] = true;
        }
      }
      mx = max(mx, cnt[i].back());
    }
    maxx[i] = mx + 1;
  }
  rev[1000010 - 1] = true;
  long long mn = 100000000000000;
  found = false;
  for (long long i = 1000010 - 2; i >= 0; i--) {
    if (cnt[i].size() == 0) {
      if (!found) rev[i] = true;
      minn[i] = minn[i + 1];
      continue;
    } else {
      long long curr = cnt[i].back();
      if (curr < mn and !found) {
        rev[i] = true;
      } else {
        if (!found) {
          found = true;
          rev[i] = true;
        }
      }
      mn = min(mn, cnt[i][0]);
    }
    minn[i] = mn + 1;
  }
  long long ans = 0;
  vector<long long> final;
  for (long long i = 1; i <= x; i++) {
    if (okay[i]) {
      final.push_back(maxx[i - 1]);
    }
    long long curr = 0, val = 0;
    if (rev[i]) {
      curr = minn[i + 1];
      val = lower_bound(final.begin(), final.end(), curr) - final.begin();
      ans += val;
    }
  }
  cout << ans << "\n";
}
