#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
vector<int> add[N];
int v[N], rem[N];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
  }
  int mx = 1, mn = 1e9;
  for (int i = n - 1; i >= 0; i--) {
    if (mn != 1e9 && v[i] > mn) {
      add[mn].push_back(v[i]);
      rem[v[i] + 1]++;
      mx = max(mx, mn);
    }
    mn = min(mn, v[i]);
  }
  mn = -1e9;
  for (int i = 0; i < n; i++) {
    if (mn != -1e9 && v[i] < mn) {
      add[v[i]].push_back(mn);
      rem[mn + 1]++;
      mx = max(mx, v[i]);
    }
    mn = max(mn, v[i]);
  }
  long long ans = 0;
  int fin = 1;
  for (int i = 1; i <= x; i++) {
    int end = i;
    end = max(end, mx);
    if (rem[i]) break;
    end = max(end, fin);
    for (int j = 0; j < add[i].size(); j++) {
      fin = max(fin, add[i][j]);
    }
    if (end <= x) ans += x - end + 1;
  }
  cout << ans << endl;
  return 0;
}
