#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int L[N], R[N];
int a[N];
int pos[N];
void solve() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= x; i++) L[i] = n + 1, R[i] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    int x = a[i];
    L[x] = min(L[x], i);
    R[x] = max(R[x], i);
  }
  int r = x, curL = n + 1;
  while (r >= 1) {
    if (R[r] < curL)
      curL = min(curL, L[r]), r--;
    else {
      r++;
      break;
    }
    pos[r + 1] = curL;
  }
  if (r == 0) {
    cout << 1LL * x * (x + 1) / 2 << endl;
    return;
  }
  long long ans = x - r + 2;
  int curR = 0;
  for (int l = 1; l <= x;) {
    curR = max(curR, R[l]);
    while (curL <= curR) {
      r++;
      if (r == x + 1)
        curL = n + 1;
      else {
        curL = pos[r];
      }
    }
    ans += (x - r + 1) + 1;
    if (L[l + 1] <= curR) break;
    assert(l != x);
    l++;
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
