#include <bits/stdc++.h>
const int MAXN = 1123456;
using namespace std;
int minpos[MAXN + 1], minpos_acc[MAXN + 1];
int maxpos[MAXN + 1], maxpos_acc[MAXN + 1];
int a[MAXN + 1];
long long cont = 0;
int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= x; i++) {
    minpos[i] = n;
    maxpos[i] = -1;
  }
  for (int i = 0; i < n; i++) {
    if (minpos[a[i]] >= i) minpos[a[i]] = i;
    if (maxpos[a[i]] <= i) maxpos[a[i]] = i;
  }
  minpos[x + 1] = n;
  maxpos[0] = -1;
  minpos_acc[x] = minpos[x];
  for (int i = x - 1; i >= 1; i--) {
    minpos_acc[i] = min(minpos[i], minpos_acc[i + 1]);
  }
  maxpos_acc[1] = maxpos[1];
  for (int i = 2; i <= x; i++) {
    maxpos_acc[i] = max(maxpos[i], maxpos_acc[i - 1]);
  }
  int r_ini = x;
  minpos_acc[x + 1] = n;
  while (r_ini >= 2 and maxpos[r_ini] <= minpos_acc[r_ini + 1]) {
    r_ini--;
  }
  int l = 1, r = r_ini;
  maxpos_acc[0] = -1;
  while (l <= x) {
    while (minpos_acc[r + 1] <= maxpos_acc[l - 1]) {
      r++;
    }
    cont += (x + 1 - r);
    if (minpos[l] <= maxpos_acc[l - 1]) break;
    l++;
    r = max(r, l);
  }
  printf("%lld\n", cont);
  return 0;
}
