#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  cin >> n >> x;
  vector<long long> a(n), b(x);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  long long a_max = x - 1, min_val = x;
  for (long long i = n - 1; i >= 0; i--) {
    if (a[i] > min_val) {
      a_max = min(a_max, a[i]);
    }
    min_val = min(min_val, a[i]);
  }
  long long j = 0, max_val = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] < max_val) {
      j = max(j, a[i]);
      b[a[i]] = max_val;
    }
    max_val = max(max_val, a[i]);
  }
  long long res = 0;
  for (long long i = 0; i < a_max + 1; i++) {
    j = max(j, i);
    res += x - j;
    j = max(j, b[i]);
  }
  cout << res << endl;
  return 0;
}
