#include <bits/stdc++.h>
using namespace std;
int arr[1000005];
int first_occ[1000005];
int last_occ[1000005];
bool ase[1000005];
int daan_e_ase[1000005];
int baam_e_ase[1000005];
bool pref_sorted[1000005];
bool suff_sorted[1000005];
void set_prefix(int n, int x, int first_ase) {
  pref_sorted[0] = true;
  for (int i = 1; i <= first_ase; ++i) pref_sorted[i] = true;
  int last_saw = first_ase;
  for (int i = first_ase + 1; i <= x; ++i) {
    if (pref_sorted[i - 1]) {
      if (ase[i] == false) {
        pref_sorted[i] = true;
      } else {
        if (first_occ[i] > last_occ[last_saw]) {
          pref_sorted[i] = true;
          last_saw = i;
        } else {
          pref_sorted[i] = false;
        }
      }
    } else {
      pref_sorted[i] = false;
    }
  }
}
void set_suffix(int n, int x, int last_ase) {
  suff_sorted[x + 1] = true;
  for (int i = x; i >= last_ase; --i) suff_sorted[i] = true;
  int last_saw = last_ase;
  for (int i = last_ase - 1; i >= 1; --i) {
    if (suff_sorted[i + 1]) {
      if (ase[i] == false) {
        suff_sorted[i] = true;
      } else {
        if (last_occ[i] < first_occ[last_saw]) {
          suff_sorted[i] = true;
          last_saw = i;
        } else {
          suff_sorted[i] = false;
        }
      }
    } else {
      suff_sorted[i] = false;
    }
  }
}
bool is_sorted(int baam, int daan, int scheck) {
  if (!suff_sorted[scheck]) return false;
  if (baam == -1 || daan == -1) return true;
  return last_occ[baam] < first_occ[daan];
}
int findr(int l, int x) {
  if (!pref_sorted[l - 1]) return 0;
  int lo = l;
  int hi = x;
  int baam = baam_e_ase[l - 1];
  while (lo + 1 < hi) {
    int mid = lo + (hi - lo) / 2;
    int scheck = mid + 1;
    int daan = daan_e_ase[scheck];
    if (is_sorted(baam, daan, scheck)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  if (is_sorted(baam, daan_e_ase[lo + 1], lo + 1))
    return (x - lo + 1);
  else if (is_sorted(baam, daan_e_ase[hi + 1], hi + 1))
    return (x - hi + 1);
  else
    return 0;
}
void pre(int n, int x) {
  int first_ase = 1000000009;
  int last_ase = -1;
  for (int i = 1; i <= n; ++i) {
    ase[arr[i]] = true;
    first_ase = min(first_ase, arr[i]);
    last_ase = max(last_ase, arr[i]);
  }
  memset(daan_e_ase, -1, sizeof(daan_e_ase));
  memset(baam_e_ase, -1, sizeof(baam_e_ase));
  for (int i = 1; i <= x; ++i) {
    if (ase[i])
      baam_e_ase[i] = i;
    else
      baam_e_ase[i] = baam_e_ase[i - 1];
  }
  for (int i = x; i >= 1; --i) {
    if (ase[i])
      daan_e_ase[i] = i;
    else
      daan_e_ase[i] = daan_e_ase[i + 1];
  }
  for (int i = 1; i <= n; ++i) {
    if (first_occ[arr[i]] == 0) first_occ[arr[i]] = i;
    last_occ[arr[i]] = i;
  }
  set_prefix(n, x, first_ase);
  set_suffix(n, x, last_ase);
}
int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  for (int i = 1; i <= n; ++i) scanf("%d", &arr[i]);
  pre(n, x);
  long long ans = 0;
  for (int l = 1; l <= x; ++l) {
    int rr = findr(l, x);
    ans = ans + rr;
  }
  printf("%lld\n", ans);
  return 0;
}
