#include <bits/stdc++.h>
using std::abs;
using std::cerr;
using std::cin;
using std::cout;
using std::function;
using std::lower_bound;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::reverse;
using std::set;
using std::sort;
using std::stoi;
using std::string;
using std::to_string;
using std::vector;
using ll = long long;
using PI = pair<int, int>;
template <class T>
using V = vector<T>;
using VI = V<int>;
int MOD = (int)1e9 + 7;
template <class T>
inline void debug(T &A) {}
template <class T>
inline void debug_dim2(T &A) {}
template <typename... Args>
inline void debug(const char *format, Args const &...args) {}
template <typename... Args>
string format(const std::string &fmt, Args... args) {
  size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args...);
  std::vector<char> buf(len + 1);
  std::snprintf(&buf[0], len + 1, fmt.c_str(), args...);
  return std::string(&buf[0], &buf[0] + len);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, X;
  cin >> N >> X;
  const PI ZERO = PI(X, 1);
  V<PI> inv(X + 1, ZERO);
  VI A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  set<int> past;
  for (int i = N - 1; i >= 0; --i) {
    past.insert(A[i]);
    auto it = past.find(A[i]);
    if (it != past.begin()) {
      inv[A[i]].second = *prev(it);
      inv[A[i]].first = *past.begin();
    }
    past.insert(A[i]);
  }
  V<PI> cum(X + 2, ZERO);
  for (int i = X; i >= 1; --i) {
    cum[i] = {min(cum[i + 1].first, inv[i].first),
              max(cum[i + 1].second, inv[i].second)};
  }
  auto test = [&](int l, int r) {
    return l <= cum[r + 1].first && cum[r + 1].second <= r;
  };
  bool leadingZero = true;
  ll ans = 0ll;
  for (int l = 1; l <= X; ++l) {
    if (leadingZero) {
      int low = l;
      int high = X + 1;
      while (low < high) {
        int mid = (low + high) / 2;
        if (test(l, mid))
          high = mid;
        else
          low = mid + 1;
      }
      if (high != X + 1) {
        int r = high;
        debug("l:%d r:%d", l, r);
        ans += X - r + 1;
      }
      if (inv[l] != ZERO) leadingZero = false;
    }
  }
  cout << ans;
  return 0;
}
