#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
long long n, m, suf, minn, ans, pos;
long long a[N], fir[N], la[N], maxn[N];
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (!fir[a[i]]) fir[a[i]] = i;
    la[a[i]] = i;
    maxn[i] = max(maxn[i - 1], a[i]);
  }
  suf = m + 1;
  minn = n + 1;
  for (long long i = m; i; i--) {
    if (!fir[i]) {
      suf = i;
      continue;
    }
    if (la[i] > minn) break;
    suf = i;
    minn = fir[i];
  }
  for (long long l = 1; l <= m; l++) {
    long long r = max(max(suf - 1, l), maxn[pos]);
    ans += m - r + 1;
    if (fir[l]) {
      if (fir[l] < pos) break;
      pos = la[l];
    }
  }
  cout << ans;
  return 0;
}
