#include <bits/stdc++.h>
using namespace std;
int n, m;
int l[1000006], r[1000006];
int pre[1000006], suf[1000006];
int read() {
  char c = getchar();
  int x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x;
}
bool check(int x, int v) {
  if (suf[x + 1] == -1) return false;
  return suf[x + 1] > v;
}
int bound(int v, int l, int r) {
  int res = 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid, v)) {
      r = mid - 1;
      res = mid;
    } else
      l = mid + 1;
  }
  return res;
}
int main() {
  memset(l, 0x3f, sizeof(l));
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i) {
    int x = read();
    l[x] = min(l[x], i);
    r[x] = max(r[x], i);
  }
  for (int i = 1; i <= m; ++i) {
    if (pre[i - 1] == -1) pre[i] = -1;
    if (l[i] != 0x3f3f3f3f) {
      if (l[i] < pre[i - 1])
        pre[i] = -1;
      else
        pre[i] = r[i];
    } else
      pre[i] = pre[i - 1];
  }
  suf[m + 1] = 0x3f3f3f3f;
  for (int i = m; i >= 1; --i) {
    if (suf[i + 1] == -1) suf[i] = -1;
    if (r[i]) {
      if (r[i] > suf[i + 1])
        suf[i] = -1;
      else
        suf[i] = l[i];
    } else
      suf[i] = suf[i + 1];
  }
  long long ans = 0;
  for (int i = 1; i <= m; ++i) {
    if (pre[i - 1] == -1) break;
    int p = bound(pre[i - 1], i, m);
    ans = ans + (m - p + 1);
  }
  printf("%I64d\n", ans);
}
