#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
template <class T>
void read(T &val) {
  T x = 0;
  T bz = 1;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') {
    bz = -1;
    c = getchar();
  }
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  val = x * bz;
}
const int mod = 998244353;
const int maxn = 1e6 + 10;
int n, m, a[maxn], q, t, k, x;
int pre[maxn];
int lp[maxn], rp[maxn];
int main() {
  read(n);
  read(x);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    pre[i] = max(a[i], pre[i - 1]);
    rp[a[i]] = i;
    lp[a[i]] = lp[a[i]] ? lp[a[i]] : i;
  }
  int l = 1, r = 1;
  for (int i = 1; i <= x; i++) {
    if (lp[i] == 0) continue;
    if (pre[rp[i]] > i) r = i;
  }
  long long ans = 0;
  int mxpos = 0;
  for (int i = 1; i <= x; i++) {
    r = max(r, i);
    ans += x - r + 1;
    if (lp[i] == 0) {
      continue;
    } else {
      r = max(r, pre[rp[i]]);
      if (lp[i] < mxpos) break;
      mxpos = rp[i];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
