#include <bits/stdc++.h>
using namespace std;
int n, m, L, R, a[1000005], l[1000005], r[1000005], f[1000005], g[1000005];
long long ans = 0;
inline int read() {
  int red = 0, f_f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f_f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') red = red * 10 + ch - '0', ch = getchar();
  return red * f_f;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) l[i] = n + 1;
  for (int i = 1; i <= n; i++) {
    a[i] = read(), r[a[i]] = i;
    if (l[a[i]] == n + 1) l[a[i]] = i;
  }
  L = n + 1, R = 0, f[0] = 0, g[m + 1] = n + 1;
  for (int i = 1; i <= m; i++) {
    if (f[i - 1] == n + 1)
      f[i] = f[i - 1];
    else {
      if (l[i] < R)
        f[i] = n + 1;
      else
        f[i] = R = max(R, r[i]);
    }
  }
  for (int i = m; i > 0; i--) {
    if (!g[i + 1])
      g[i] = g[i + 1];
    else {
      if (r[i] > L)
        g[i] = 0;
      else
        g[i] = L = min(L, l[i]);
    }
  }
  for (int i = 1; i <= m; i++)
    ans += m + 2 - (upper_bound(g + i + 1, g + m + 2, f[i - 1]) - g);
  printf("%lld\n", ans);
  return 0;
}
