#include <bits/stdc++.h>
const int N = 1000010;
const int INF = 0x3f3f3f3f;
int x;
class ArrayEqual {
 public:
  ArrayEqual() {}
  void Build(int n, int val_max, int a[], int pre[], int nxt[], int first[],
             int last[]) {
    for (int i = 0; i <= val_max; ++i) {
      first[i] = 0;
      last[i] = n + 1;
    }
    for (int i = 1; i <= n; ++i) {
      nxt[i] = n + 1;
      pre[i] = 0;
    }
    for (int i = 1; i <= n; ++i) {
      if (!first[a[i]]) {
        first[a[i]] = i;
        pre[i] = 0;
      } else {
        pre[i] = last[a[i]];
        nxt[pre[i]] = i;
      }
      last[a[i]] = i;
    }
  }

 private:
} array_equal;
int first[N];
int last[N];
class Bit {
 public:
  Bit() {}
  void Init(int n) {
    n_ = n;
    for (int i = 1; i <= n; ++i) {
      mi[i] = INF;
      mx[i] = -INF;
      sum[i] = 0ll;
      mi_suf[i] = INF;
    }
  }
  void Change(int id, long long x) {
    for (int i = id; i <= n_; i += (i & (-i))) {
      mi[i] = std::min(mi[i], x);
      mx[i] = std::max(mx[i], x);
    }
    long long inc = x - (PreSum(id) - PreSum(id - 1));
    Increase(id, inc);
    int id_inv = n_ - id + 1;
    for (int i = id_inv; i <= n_; i += (i & (-i))) {
      mi_suf[i] = std::min(mi_suf[i], x);
    }
  }
  void Increase(int id, long long x) {
    for (int i = id; i <= n_; i += (i & (-i))) {
      sum[i] += x;
    }
  }
  long long PreMin(int id) {
    if (id <= 0) {
      return INF;
    }
    long long ans = INF;
    for (int i = id; i; i -= (i & (-i))) {
      ans = std::min(ans, mi[i]);
    }
    return ans;
  }
  long long PreMax(int id) {
    long long ans = -INF;
    if (id <= 0) {
      return -INF;
    }
    for (int i = id; i; i -= (i & (-i))) {
      ans = std::max(ans, mx[i]);
    }
    return ans;
  }
  long long PreSum(int id) {
    if (id <= 0) {
      return 0;
    }
    long long ans = 0;
    for (int i = id; i; i -= (i & (-i))) {
      ans += sum[i];
    }
    return ans;
  }
  long long SufMin(int id) {
    int id_inv = n_ - id + 1;
    if (id_inv <= 0) {
      return INF;
    }
    long long ans = INF;
    for (int i = id_inv; i; i -= (i & (-i))) {
      ans = std::min(ans, mi_suf[i]);
    }
    return ans;
  }
  int SumInterval(int l, int r) { return PreSum(r) - PreSum(l - 1); }

 private:
  int n_;
  long long mi[N];
  long long mx[N];
  long long sum[N];
  long long mi_suf[N];
} bit;
class Discretization {
 public:
  Discretization() { vec_.clear(); }
  void Init() { vec_.clear(); }
  void Add(int x) { vec_.push_back(x); }
  void Build() {
    std::sort(vec_.begin(), vec_.end());
    vec_.erase(std::unique(vec_.begin(), vec_.end()), vec_.end());
  }
  int Id(int x) {
    auto y = std::lower_bound(vec_.begin(), vec_.end(), x);
    if (*y != x) {
      return -1;
    } else {
      return y - vec_.begin() + 1;
    }
  }
  int Size() { return vec_.size(); }
  int Value(int id) { return vec_[id - 1]; }

 private:
  std::vector<int> vec_;
} disc;
int t;
int n, m;
int a[N];
int b[N];
int pre[N], nxt[N];
int main() {
  scanf("%d%d", &n, &x);
  disc.Init();
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    disc.Add(a[i]);
  }
  array_equal.Build(n, x, a, pre, nxt, first, last);
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    if (nxt[i] == n + 1) {
      if (!mx || mx <= a[i]) {
        b[a[i]] = a[i];
      } else {
        b[a[i]] = mx;
      }
    }
    mx = std::max(mx, a[i]);
  }
  disc.Build();
  m = disc.Size();
  int cnt = 1;
  long long ans = 0ll;
  int r_min = 1;
  for (int i = m - 1; i >= 1; --i) {
    int cur = disc.Value(i);
    int pre = disc.Value(i + 1);
    if (last[cur] > first[pre]) {
      r_min = cur;
      break;
    }
  }
  int l_max = x;
  for (int i = 2; i <= m; ++i) {
    int cur = disc.Value(i);
    int pre = disc.Value(i - 1);
    if (first[cur] < last[pre]) {
      l_max = cur;
      break;
    }
  }
  bit.Init(x + 1);
  for (int r = 1; r <= x; ++r) {
    if (r >= r_min) {
      int tmp = bit.SufMin(r + 1);
      if (tmp == INF) {
        ans += std::min(r, l_max);
      } else {
        ans += std::min(tmp, l_max);
      }
    }
    if (cnt <= m) {
      int val = disc.Value(cnt);
      if (val == r) {
        bit.Change(b[val], val);
        ++cnt;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
