#include <bits/stdc++.h>
using namespace std;
const int N = 1100000;
long long ans;
int n, x, a[N], minVal[N][20], maxVal[N][21], qlg[N];
vector<int> pos[N];
template <class T>
inline void read(T &x) {
  x = 0;
  char ch = getchar(), w = 0;
  while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = w ? -x : x;
  return;
}
inline bool judge(int mid) {
  int now = 0;
  for (register int i = 1; i <= n; ++i)
    if (a[i] > mid) {
      if (a[i] >= now)
        now = a[i];
      else
        return 0;
    }
  return 1;
}
inline int min(int a, int b) { return a < b ? a : b; }
inline int max(int a, int b) { return a > b ? a : b; }
inline int queryMin(int l, int r) {
  int len = r - l + 1;
  return min(minVal[l][qlg[len]], minVal[r - (1 << qlg[len]) + 1][qlg[len]]);
}
inline int queryMax(int l, int r) {
  int len = r - l + 1;
  return max(maxVal[l][qlg[len]], maxVal[r - (1 << qlg[len]) + 1][qlg[len]]);
}
int main() {
  read(n), read(x);
  int lim = max(n, x);
  for (register int i = 1; i <= n; ++i) read(a[i]), pos[a[i]].push_back(i);
  for (register int i = 2; i <= n; ++i) qlg[i] = qlg[i >> 1] + 1;
  for (register int i = 1; i <= n; ++i)
    minVal[i][0] = a[i], maxVal[i][0] = a[i];
  for (register int i = 1; i <= qlg[n]; ++i)
    for (register int j = 1; j <= n - (1 << i) + 1; ++j) {
      minVal[j][i] = min(minVal[j][i - 1], minVal[j + (1 << i >> 1)][i - 1]);
      maxVal[j][i] = max(maxVal[j][i - 1], maxVal[j + (1 << i >> 1)][i - 1]);
    }
  int l = 1, r = x;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (judge(mid))
      r = mid;
    else
      l = mid + 1;
  }
  ans = x - r + 1;
  for (register int i = 1; i < x; ++i) {
    int sz = pos[i].size();
    r = max(r, i + 1);
    if (!sz) {
      ans += x - r + 1;
      continue;
    }
    r = max(r, queryMax(1, pos[i][sz - 1]));
    if (queryMin(pos[i][0], n) < i) break;
    ans += x - r + 1;
  }
  cout << ans;
  return 0;
}
