#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, xx;
  cin >> n >> x;
  xx = x + 5;
  vector<int> l(xx, n), r(xx, -1), ll(xx, n), rr(xx, -1);
  for (int i = 0; i < n; i++) {
    int z;
    cin >> z;
    l[z] = min(l[z], i);
    r[z] = max(r[z], i);
  }
  for (int i = 1; i <= x + 1; i++) rr[i] = max(rr[i - 1], r[i]);
  for (int i = x; i >= 0; i--) ll[i] = min(ll[i + 1], l[i]);
  long long ans = 0, R = x;
  while (R >= 1 && ll[R] >= r[R - 1]) R--;
  for (int i = 0; i < x; i++) {
    if (i != 0 && l[i] <= rr[i - 1]) break;
    while (ll[R] < rr[i] || R <= i + 1) R++;
    ans += x + 2 - R;
  }
  cout << ans << endl;
}
