#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 1;
int a[MAXN], b[MAXN];
int n, x;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> x;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]] = mx;
    mx = max(mx, a[i]);
  }
  int mn = x;
  int bad = x;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] > mn) {
      bad = min(a[i], bad);
    }
    mn = min(mn, a[i]);
  }
  int L = 0;
  int R = x;
  while (R - L > 1) {
    int M = (L + R) / 2;
    bool is_sorted = 1;
    int last = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] <= M) continue;
      if (last > a[i]) {
        is_sorted = 0;
        break;
      }
      last = a[i];
    }
    (is_sorted ? R : L) = M;
  }
  long long ans = x - R + 1;
  for (int y = 1; y < bad; y++) {
    R = max(max(R, b[y]), y + 1);
    ans += (long long)(x - R + 1);
  }
  cout << ans << '\n';
  return 0;
}
