#include <bits/stdc++.h>
using namespace std;
long long a[1000001];
long long s[4000004];
long long la[1000001];
long long fi[1000001];
long long getMax(long long l, long long r, long long il, long long ir,
                 long long i) {
  if (l >= il && r <= ir)
    return s[i];
  else if (l > ir || r < il)
    return INT_MIN;
  else {
    long long mid = (l + r) / 2;
    return max(getMax(l, mid, il, ir, 2 * i),
               getMax(mid + 1, r, il, ir, 2 * i + 1));
  }
}
long long createSegTreeMax(long long l, long long r, long long i) {
  if (l == r) {
    s[i] = a[l];
    return s[i];
  }
  long long mid = (l + r) / 2;
  s[i] = max(createSegTreeMax(l, mid, 2 * i),
             createSegTreeMax(mid + 1, r, 2 * i + 1));
  return s[i];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, x;
  cin >> n >> x;
  for (long long i = (1), _b = (n); i <= _b; i++) {
    cin >> a[i];
  }
  for (long long i = 0, _n = (x + 1); i < _n; i++) {
    la[i] = 0;
    fi[i] = n + 1;
  }
  for (long long i = (1), _b = (n); i <= _b; i++) {
    la[a[i]] = i;
    if (fi[a[i]] == n + 1) fi[a[i]] = i;
  }
  long long ans = 0;
  createSegTreeMax(1, n, 1);
  long long xx = 1;
  long long pre = 1;
  for (long long i = 2; i <= x; i++) {
    if (fi[i] == n + 1) {
      pre++;
    } else if (fi[i] > la[xx]) {
      pre++;
      xx = i;
    } else
      break;
  }
  long long suff = x;
  xx = x;
  for (long long i = x - 1; i >= 1; i--) {
    if (la[i] == 0)
      suff--;
    else if (la[i] < fi[xx]) {
      xx = i;
      suff--;
    } else
      break;
  }
  if (pre == x) {
    cout << (x * (x + 1)) / 2 << endl;
    return 0;
  }
  for (long long i = (1), _b = (pre); i <= _b; i++) {
    if (la[i] == 0) la[i] = la[i - 1];
  }
  for (long long i = (1), _b = (pre); i <= _b; i++) {
    long long maxi;
    if (la[i] != 0)
      maxi = getMax(1, n, 1, la[i], 1);
    else
      maxi = suff - 1;
    maxi++;
    if (maxi < suff) maxi = suff;
    ans = ans + (x - maxi + 2);
  }
  ans = ans + (x - suff + 2);
  cout << ans << endl;
}
