#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int l[N], r[N], ll[N], rr[N];
int main() {
  int n, mx;
  scanf("%d%d", &n, &mx);
  for (int i = 0; i <= mx + 1; ++i) l[i] = ll[i] = n + 1;
  for (int i = 1, x; i <= n; ++i)
    scanf("%d", &x), l[x] = min(l[x], i), r[x] = i;
  for (int i = 1; i <= mx; ++i) rr[i] = max(rr[i - 1], r[i]);
  for (int i = mx; i >= 1; --i) ll[i] = min(ll[i + 1], l[i]);
  int R = mx - 1;
  while (r[R] < ll[R + 1] && R > 1) --R;
  if (R < 1) R = 1;
  long long ans = mx - R + 1;
  for (int L = 2; l[L - 1] > rr[L - 2] && L <= mx; ++L) {
    while ((R < L || r[L - 1] > ll[R + 1]) && R < mx) ++R;
    ans += mx - R + 1;
  }
  printf("%lld\n", ans);
}
