#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
const long long Maxn = 1e6 + 10;
const long long INF = 1e18;
using pll = pair<long long, long long>;
long long mn_pos[Maxn], mx_pos[Maxn];
long long pre_mx[Maxn], suc_mn[Maxn];
bool check_l[Maxn], check_r[Maxn];
long long a[Maxn];
bool check(long long l, long long r) {
  if (!check_l[l - 1]) return 0;
  if (!check_r[r + 1]) return 0;
  if (pre_mx[l - 1] > suc_mn[r + 1]) return 0;
  return 1;
}
int main() {
  long long n, x;
  scanf("%lld%lld", &n, &x);
  for (long long i = 1; i <= n; i++) scanf("%lld", a + i);
  for (long long i = 0; i <= x + 1; i++) {
    mn_pos[i] = suc_mn[i] = INF;
    mx_pos[i] = pre_mx[i] = -INF;
  }
  for (long long i = 1; i <= n; i++) {
    mn_pos[a[i]] = min(mn_pos[a[i]], i);
    mx_pos[a[i]] = max(mx_pos[a[i]], i);
  }
  for (long long i = 1; i <= x; i++) pre_mx[i] = max(pre_mx[i - 1], mx_pos[i]);
  for (long long i = x; i >= 1; i--) suc_mn[i] = min(suc_mn[i + 1], mn_pos[i]);
  check_l[0] = check_r[x + 1] = 1;
  for (long long i = 1; i <= x; i++)
    check_l[i] = check_l[i - 1] && (mn_pos[i] > pre_mx[i - 1]);
  for (long long i = x; i >= 1; i--)
    check_r[i] = check_r[i + 1] && (mx_pos[i] < suc_mn[i + 1]);
  long long l = 1, r = 1, ans = 0;
  while (l <= x) {
    if (check(l, r)) {
      ans += (x - r + 1);
      if (l < r)
        l++;
      else {
        if (r < x)
          l++, r++;
        else
          break;
      }
    } else {
      if (r < x)
        r++;
      else
        l++;
    }
  }
  printf("%lld", ans);
  return 0;
}
