#include <bits/stdc++.h>
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long i, n, x;
  cin >> n >> x;
  long long a[n], pr[x + 2], sf[x + 2];
  fill(pr, pr + x + 2, n + 1);
  fill(sf, sf + x + 2, -1);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sf[a[i]] = i + 1;
    if (pr[a[i]] == n + 1) pr[a[i]] = i + 1;
  }
  vector<long long> p(x + 2, n + 2);
  vector<long long> s(x + 2, -1);
  s[x + 1] = n + 1;
  p[0] = 0;
  for (i = 1; i <= x; i++) {
    if (pr[i] != n + 1 && pr[i] > p[i - 1])
      p[i] = sf[i];
    else if (pr[i] == n + 1)
      p[i] = p[i - 1];
    else
      break;
  }
  for (i = x; i >= 1; i--) {
    if (sf[i] != -1 && sf[i] < s[i + 1])
      s[i] = pr[i];
    else if (sf[i] == -1)
      s[i] = s[i + 1];
    else
      break;
  }
  long long t;
  long long ans = 0;
  for (i = 0; i < x; i++) {
    vector<long long>::iterator it = lower_bound(s.begin(), s.end(), p[i]);
    if (it != s.begin()) {
      t = it - s.begin();
      t = max(t, i + 2);
      ans += max(x - t + 2, 0ll);
    }
  }
  cout << ans;
  return 0;
}
