#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma,sse,sse2,ssse3,tune=native")
#pragma GCC optimize("unroll-loops")
const int MAX_MEM = 1e8;
int mpos = 0;
char mem[MAX_MEM];
inline void *operator new(size_t n) {
  char *res = mem + mpos;
  mpos += n;
  assert(mpos <= MAX_MEM);
  return (void *)res;
}
inline void operator delete(void *) noexcept {}
inline void *operator new[](size_t) { assert(0); }
inline void operator delete[](void *) noexcept { assert(0); }
using ll = long long;
using namespace std;
const int N = 1e6 + 6, mod = 1e9 + 7;
int n, x, r = 0, LIS = 0, a[N];
ll ans = 0;
bitset<N> tuna, uno;
set<int> s;
vector<int> id[N];
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s.insert(i);
    id[a[i]].push_back(i);
  }
  a[n + 1] = INT_MAX;
  for (int i = 1; i <= n; i++) {
    if (a[i - 1] <= a[i]) {
      tuna[i] = 1;
    }
    if (a[i] <= a[i + 1]) {
      uno[i] = 1;
    }
    if (tuna[i] && uno[i]) {
      LIS++;
    }
  }
  tuna[0] = 1;
  uno[n + 1] = 1;
  for (int l = 1; l <= x; l++) {
    for (auto cid : id[l - 1]) {
      auto it = s.lower_bound(cid);
      int L = 0, R = n + 1;
      if (it != s.end()) {
        R = *it;
      }
      if (it != s.begin()) {
        L = *--it;
      }
      if (!(L == 0 && R == n + 1) && a[L] <= a[R]) {
        if (L != 0 && tuna[L] && uno[L]) {
          LIS--;
        }
        if (R != n + 1 && tuna[R] && uno[R]) {
          LIS--;
        }
        uno[L] = tuna[R] = 0;
      }
      if (L != 0 && a[L] <= l) {
        if (!uno[L]) {
          if (tuna[L]) {
            LIS++;
          }
          uno[L] = 1;
        }
      }
      if (R != n + 1 && l <= a[R]) {
        if (!tuna[R]) {
          if (uno[R]) {
            LIS++;
          }
          tuna[R] = 1;
        }
      }
      if (a[L] <= l) {
        tuna[cid] = 1;
      }
      if (l <= a[R]) {
        uno[cid] = 1;
      }
      if (a[L] <= l && l <= a[R]) {
        LIS++;
      }
      s.insert(cid);
    }
    while (r < l || LIS != int(s.size())) {
      r++;
      if (r > x) {
        break;
      }
      for (auto cid : id[r]) {
        if (tuna[cid] && uno[cid]) {
          LIS--;
        }
        tuna[cid] = uno[cid] = 0;
        auto it = s.find(cid);
        int L = 0, R = n + 1;
        if (it != s.begin()) {
          L = *--it;
          it++;
        }
        if (++it != s.end()) {
          R = *it;
        }
        if (!(L == 0 && R == n + 1) && a[L] <= a[R]) {
          if (L != 0 && !uno[L]) {
            if (tuna[L]) {
              LIS++;
            }
            uno[L] = 1;
          }
          if (R != n + 1 && !tuna[R]) {
            if (uno[R]) {
              LIS++;
            }
            tuna[R] = 1;
          }
        }
        s.erase(cid);
      }
    }
    if (LIS == int(s.size())) {
      ans += x - r + 1;
    }
  }
  cout << ans;
}
