#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
int n, x;
int a[maxn + 1];
vector<int> V[maxn + 1];
vector<int> curr;
stack<int> last;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    V[a[i]].push_back(i);
  }
  int j;
  for (j = x; j >= 1; j--) {
    bool flag = true;
    for (auto it = V[j].rbegin(); it != V[j].rend(); it++) {
      if (last.empty() or last.top() > *it)
        last.push(*it);
      else {
        flag = false;
        while (it != V[j].rbegin()) {
          it--;
          last.pop();
        }
        break;
      }
    }
    if (!flag) break;
  }
  j++;
  long long res = 0;
  res = min(x, (x - j + 2));
  bool flag = true;
  for (int i = 1; i < x; i++) {
    for (auto it = V[i].begin(); it != V[i].end(); it++) {
      if (curr.empty() or *it > *curr.rbegin())
        curr.push_back(*it);
      else {
        flag = false;
        break;
      }
    }
    if (!flag) break;
    if (flag) {
      while (1 <= j and j <= x and !last.empty() and !curr.empty() and
             *curr.rbegin() > last.top()) {
        for (auto it = V[j].begin(); it != V[j].end(); it++) last.pop();
        j++;
      }
      res += min((long long)(x - i), (long long)(x - j + 2));
    }
  }
  cout << res;
}
