#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <class T>
inline bool setmin(T &a, T b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <class T>
inline bool setmax(T &a, T b) {
  if (a < b) return a = b, 1;
  return 0;
}
namespace fastio {
template <class T>
istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container) os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container) os << u << " ";
  return os;
}
template <class T1, class T2>
inline istream &operator>>(istream &os, pair<T1, T2> &p) {
  return os >> p.first >> p.second;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << p.first << " " << p.second;
}
template <class T>
ostream &operator<<(ostream &os, set<T> const &con) {
  for (auto &u : con) os << u << " ";
  return os;
}
void re() {}
template <typename T, typename... args>
void re(T &x, args &...tail) {
  cin >> x;
  re(tail...);
}
void pr() {}
template <typename T, typename... args>
void pr(T x, args... tail) {
  cout << x << " ";
  pr(tail...);
}
template <typename... args>
void prln(args... tail) {
  pr(tail...);
  cout << "\n";
}
}  // namespace fastio
using namespace fastio;
namespace debug {
template <typename _T>
inline void _debug(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _debug(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _debug(s + 1, a...);
}
}  // namespace debug
using namespace debug;
constexpr int MOD = 1e9 + 7;
constexpr int INF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
const int N = 1e6 + 7;
int n, x, a[N], minn[N], maxx[N];
bitset<N> pocz, kon;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  re(n, x);
  for (int i = (1); i <= (n); i++) re(a[i]);
  for (int i = (1); i <= (x); i++) {
    maxx[i] = 0;
    minn[i] = INF;
  }
  set<int> A = {0, INF};
  for (int i = (n); i >= (1); i--) {
    auto it1 = ++A.begin();
    auto it2 = A.lower_bound(a[i]);
    if (it1 != A.end() and *it1 != INF and *it1 < a[i]) {
      setmin(minn[*it1], a[i]);
      setmax(maxx[*it1], a[i]);
    }
    if (it2 != A.begin() and *(--it2) != INF and *it2 < a[i]) {
      setmin(minn[*it2], a[i]);
      setmax(maxx[*it2], a[i]);
    }
    A.insert(a[i]);
  }
  for (int i = (1); i <= (x); i++) {
    1999;
  }
  int maks = 0;
  for (int i = (1); i <= (x); i++) {
    if (minn[i] != INF) {
      pocz[i] = 1;
      setmax(maks, i);
      kon[minn[i]] = 1;
    }
  }
  ll res = 0;
  for (int i = (1); i <= (x); i++) {
    int temp = max(i, maks);
    res += x - temp + 1;
    if (pocz[i]) {
      kon[maxx[i]] = 1;
      setmax(maks, maxx[i]);
    }
    if (kon[i]) {
      break;
    }
  }
  prln(res);
  exit(0);
}
