#include <bits/stdc++.h>
using namespace std;
int oo = round(1e9), ma[1000001], mi[1000001], n, x, i, k;
long long kq, t;
struct pt {
  int k, Ma, Mi;
};
pt st[4000001];
pt operator+(const pt &a, const pt &b) {
  pt kq;
  kq.k = a.k || b.k || (a.Ma > b.Mi);
  kq.Ma = max(a.Ma, b.Ma);
  kq.Mi = min(a.Mi, b.Mi);
  return kq;
}
void build(int id, int l, int r) {
  if (l == r) {
    st[id] = {0, ma[l], mi[l]};
    return;
  }
  int mid = (l + r) >> 1;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
  st[id] = st[id * 2] + st[id * 2 + 1];
}
pt get(int id, int l, int r, int u, int v) {
  if (u > v) return {0, 1, n};
  if (v < l || u > r) return {0, -oo, oo};
  if (u <= l && r <= v) return st[id];
  int mid = (l + r) >> 1;
  return get(id * 2, l, mid, u, v) + get(id * 2 + 1, mid + 1, r, u, v);
}
struct pt2 {
  int c1, c2;
};
pt2 st2[4000001];
pt2 operator*(const pt2 &a, const pt2 &b) { return {a.c1 + b.c1, a.c2 + b.c2}; }
int d;
void update(int id, int l, int r, int u) {
  if (u < l || u > r) return;
  if (l == r) {
    st2[id].c1++;
    st2[id].c2 += d;
    return;
  }
  int mid = (l + r) >> 1;
  update(id * 2, l, mid, u);
  update(id * 2 + 1, mid + 1, r, u);
  st2[id] = st2[id * 2] * st2[id * 2 + 1];
}
pt2 get2(int id, int l, int r, int u, int v) {
  if (u > v) return {0, 0};
  if (v < l || u > r) return {0, 0};
  if (u <= l && r <= v) return st2[id];
  int mid = (l + r) >> 1;
  return get2(id * 2, l, mid, u, v) * get2(id * 2 + 1, mid + 1, r, u, v);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  for (i = 1; i <= x; i++) {
    ma[i] = -oo;
    mi[i] = oo;
  }
  for (i = 1; i <= n; i++) {
    cin >> k;
    ma[k] = max(ma[k], i);
    mi[k] = min(mi[k], i);
  }
  build(1, 1, x);
  for (i = 1; i <= x; i++) {
    pt tg = get(1, 1, x, i + 1, x);
    pt2 tg2 = get2(1, 1, n, tg.Mi + 1, n);
    if (tg.k == 0) kq += i - (t + tg2.c1 - tg2.c2);
    int Ma = get(1, 1, x, 1, i).Ma;
    d = get(1, 1, x, 1, i).k;
    t += d;
    update(1, 1, n, Ma);
  }
  cout << kq;
}
