#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int l[maxn], r[maxn];
int b[maxn];
long long cnt[maxn];
int main() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  memset(l, 0x3f, sizeof(l));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    l[b[i]] = min(l[b[i]], i);
    r[b[i]] = max(r[b[i]], i);
    cnt[b[i]]++;
  }
  long long L = n + 1, R = -1, pos = -1;
  long long tot = 0, ans = 0;
  for (int i = m; i >= 1; i--) {
    if (cnt[i] == 0) {
      l[i] = l[i + 1];
      continue;
    }
    if (r[i] < L) {
      L = l[i];
    } else {
      tot = m - i + 1;
      pos = i + 1;
      break;
    }
  }
  if (pos == -1) {
    ans = (m * (m + 1)) / 2;
    printf("%lld\n", ans);
    return 0;
  }
  for (int i = 0; i <= m; i++) {
    if (cnt[i] == 0) {
      ans += tot;
      continue;
    }
    if (l[i] < R) {
      break;
    } else {
      if (cnt[i] == 0) r[i] = r[i - 1];
      R = r[i];
      while (L <= R && pos <= m) {
        if (cnt[pos] == 0) {
          tot--;
          pos++;
          L = l[pos];
        } else {
          pos++;
          tot--;
          L = l[pos];
        }
      }
      ans += tot;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
