#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000010;
vector<int> V[MAX];
int ara[MAX];
int rng_mx[MAX];
int main() {
  int n, m, mn = 100000000, mx = 0;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ara[i]);
    V[ara[i]].push_back(i);
    mn = min(mn, ara[i]);
    mx = max(mx, ara[i]);
  }
  rng_mx[1] = ara[1];
  for (int i = 2; i <= n; i++) rng_mx[i] = max(rng_mx[i - 1], ara[i]);
  int left = mn;
  int cur = V[mn].back();
  for (int i = mn + 1; i <= m; i++) {
    if (V[i].size() == 0)
      left++;
    else {
      if (V[i][0] > cur) {
        cur = V[i].back();
        left++;
      } else
        break;
    }
  }
  int right = mx;
  cur = V[mx][0];
  for (int i = mx - 1; i >= 1; i--) {
    if (V[i].size() == 0)
      right--;
    else {
      if (V[i].back() < cur) {
        cur = V[i][0];
        right--;
      } else
        break;
    }
  }
  long long ans = 1;
  ans += left;
  if (left == m) ans--;
  ans += (m - right + 1);
  if (right == 1) ans--;
  int cmax = 0;
  for (int i = 1; i <= left; i++) {
    if (V[i].size() != 0) {
      cmax = rng_mx[V[i].back()];
    }
    if (cmax < right) {
      int L = right - 1;
      if (L < (i + 1)) L = i + 1;
      int R = m - 1;
      ans += max(0, R - L + 1);
    } else {
      int L = cmax;
      if (L < (i + 1)) L = i + 1;
      int R = m - 1;
      ans += max(0, R - L + 1);
    }
  }
  cout << ans << endl;
  return 0;
}
