#include <bits/stdc++.h>
using namespace std;
long long n, x, arr[1000005], kiri[1000005], kanan[1000005], le[1000005],
    ri[1000005], tmp, ans;
int main() {
  cin >> n >> x;
  for (long long i = 1; i <= x; i++) kiri[i] = n + 1;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
    if (kiri[arr[i]] == n + 1) kiri[arr[i]] = i;
    kanan[arr[i]] = i;
  }
  le[0] = 0;
  for (long long i = 1; i <= x; i++) {
    if (kiri[i] == n + 1)
      le[i] = le[i - 1];
    else if (kiri[i] < le[i - 1])
      le[i] = n + 1;
    else
      le[i] = kanan[i];
  }
  ri[x + 1] = n + 1;
  for (long long i = x; i >= 1; i--) {
    if (kanan[i] == 0)
      ri[i] = ri[i + 1];
    else if (kanan[i] > ri[i + 1])
      ri[i] = 0;
    else
      ri[i] = kiri[i];
  }
  tmp = 1;
  ans = 0;
  for (long long i = 0; i < x; i++) {
    while (tmp - i < 2 || ri[tmp] <= le[i]) {
      tmp++;
      if (tmp == x + 2) {
        cout << ans << endl;
        return 0;
      }
    }
    ans += x - tmp + 2;
  }
  cout << ans << endl;
}
