#include <bits/stdc++.h>
using namespace std;
const string yes = "YES", no = "NO";
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10),
      cout << fixed;
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int l = x, mn = 1e9;
  for (int i = n - 1; i >= 0; i -= 1) {
    if (mn < a[i]) l = min(l, a[i]);
    mn = min(mn, a[i]);
  }
  int r = 1, mx = 0;
  for (int i = 0; i < n; ++i) {
    if (mx > a[i]) r = max(r, a[i]);
    mx = max(mx, a[i]);
  }
  vector<int> MN(x + 1, x);
  mn = INT_MAX;
  for (int i = n - 1; ~i; --i) {
    MN[a[i]] = mn;
    mn = min(mn, a[i]);
  }
  for (int i = x - 1; ~i; --i) MN[i] = min(MN[i], MN[i + 1]);
  long long ans = 0;
  for (int i = 1, j = r; i <= l; ++i) {
    while (j <= x && (j < i || MN[j] < i)) ++j;
    ans += x - j + 1 + (j > max(i, r));
  }
  cout << ans << '\n';
  return 0;
}
