#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b,
                    long long int m = 1000000007) {
  if (b == 0) return 1;
  long long int c = power(a, b >> 1, m);
  c = (c * c) % m;
  if (b & 1) return (c * a) % m;
  return c;
}
long long int gcdll(long long int a, long long int b) {
  if (b == 0) return a;
  return gcdll(b, a % b);
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const int N = (int)1e6 + 5;
const int Q = 300;
int a[N], n;
bool check1(int k) {
  int last = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] < k) {
      if (a[i] < last) {
        return false;
      }
      last = a[i];
    }
  }
  return true;
}
bool check2(int k) {
  int last = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > k) {
      if (a[i] < last) {
        return false;
      }
      last = a[i];
    }
  }
  return true;
}
int rec[N];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int x;
  cin >> n >> x;
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mx = max(a[i], mx);
    rec[a[i]] = mx;
    pq.push({a[i], i});
  }
  int L, R, lo, hi, mi;
  lo = 1, hi = x;
  while (lo < hi) {
    mi = 1 + (lo + hi) / 2;
    if (check1(mi))
      lo = mi;
    else
      hi = mi - 1;
  }
  L = lo;
  lo = 1, hi = x;
  while (lo < hi) {
    mi = (lo + hi) / 2;
    if (check2(mi))
      hi = mi;
    else
      lo = mi + 1;
  }
  R = lo;
  int r = R;
  long long int ans = 0;
  for (int l = 1; l <= L; l++) {
    while (!pq.empty() && pq.top().first < l) {
      pair<int, int> temp = pq.top();
      pq.pop();
      r = max(r, rec[temp.first]);
    }
    r = max(r, l);
    ans += (long long int)(x - r + 1);
  }
  cout << ans;
}
