#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, x, a[N], pre[N], suf[N], preMx[N], sufMn[N], mn[N], mx[N];
bool check(int l, int r) {
  if (pre[l - 1] && suf[r + 1] && preMx[l - 1] <= sufMn[r + 1]) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  memset(mn, '?', sizeof(mn));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mx[a[i]] = max(mx[a[i]], i);
    mn[a[i]] = min(mn[a[i]], i);
  }
  sufMn[x + 1] = 1e9;
  for (int i = 1; i <= x; i++) {
    preMx[i] = max(mx[i], preMx[i - 1]);
  }
  for (int i = x; i > 0; i--) {
    sufMn[i] = min(mn[i], sufMn[i + 1]);
  }
  pre[0] = 1, suf[x + 1] = 1;
  for (int i = 1; i <= x; i++) {
    if (mn[i] > preMx[i - 1])
      pre[i] = 1;
    else
      break;
  }
  for (int i = x; i > 0; i--) {
    if (mx[i] < sufMn[i + 1])
      suf[i] = 1;
    else
      break;
  }
  long long ans = 0, j = 1;
  for (int i = 1; i <= x; i++) {
    while (j < i) j++;
    while (!check(i, j) && j <= x) {
      j++;
    }
    ans += (x - j + 1);
  }
  cout << ans << '\n';
  return 0;
}
