#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
const int N = 1000000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;
const int delta = 11353;
int n, x, a[N], premx[N], premn[N], sufmx[N], sufmn[N];
bool isval(int l, int r) {
  if (sufmx[r + 1] > r || sufmn[r + 1] < l || premn[l - 1] < l) return 0;
  return 1;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  set<int> st;
  fill(premx, premx + x + 2, -INF), fill(sufmx, sufmx + x + 2, -INF);
  fill(premn, premn + x + 2, INF), fill(sufmn, sufmn + x + 2, INF);
  st.insert(a[n]);
  for (int i = n - 1; i >= 1; i--) {
    if (*st.begin() < a[i]) {
      premn[a[i]] = min(premn[a[i]], *st.begin()),
      sufmn[a[i]] = min(sufmn[a[i]], *st.begin());
      auto koj = st.lower_bound(a[i]);
      koj--;
      premx[a[i]] = max(premx[a[i]], *koj);
      sufmx[a[i]] = max(sufmx[a[i]], *koj);
    }
    st.insert(a[i]);
  }
  for (int i = 1; i <= x; i++)
    premx[i] = max(premx[i - 1], premx[i]),
    premn[i] = min(premn[i - 1], premn[i]);
  for (int i = x; i >= 1; i--)
    sufmx[i] = max(sufmx[i + 1], sufmx[i]),
    sufmn[i] = min(sufmn[i + 1], sufmn[i]);
  int pnt = x + 1;
  long long ans = 0;
  for (int l = x; l >= 1; l--) {
    while (pnt != l && isval(l, pnt - 1)) pnt--;
    ans += x - pnt + 1;
  }
  cout << ans;
  return 0;
}
