#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int precan[N], sufcan[N];
int S[N], T[N], a[N];
int premax[N], sufmin[N];
bool check(int l, int r) {
  if (!precan[l - 1] || !sufcan[r + 1]) return 0;
  if (premax[l - 1] <= sufmin[r + 1]) return 1;
  return 0;
}
int main() {
  memset(S, 0x3f, sizeof S);
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), S[a[i]] = min(S[a[i]], i), T[a[i]] = max(T[a[i]], i);
  ;
  sufmin[x + 1] = 1e9;
  for (int i = 1; i <= x; ++i) premax[i] = max(premax[i - 1], T[i]);
  for (int i = x; i >= 0; --i) sufmin[i] = min(sufmin[i + 1], S[i]);
  sufcan[x + 1] = 1;
  precan[0] = 1;
  sufcan[x] = 1;
  precan[1] = 1;
  for (int i = 1; i <= x; ++i)
    precan[i] = precan[i - 1] && (premax[i - 1] < S[i]);
  for (int i = x; i >= 0; --i)
    sufcan[i] = sufcan[i + 1] && (sufmin[i + 1] > T[i]);
  long long res = 0;
  for (int l = 1, r = 1; l <= x; ++l) {
    if (l > r) ++r;
    while (r < x && !check(l, r)) ++r;
    if (check(l, r)) res += x - r + 1;
  }
  printf("%lld", res);
  return 0;
}
