#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, x;
int a[N], l[N], r[N], lll[N], rr[N];
int main() {
  scanf("%d%d", &n, &x);
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] < a[i - 1]) flag = 0;
  }
  if (flag) {
    printf("%lld\n", 1ll * x * (x + 1) / 2);
    return 0;
  }
  for (int i = 1; i <= x; i++) l[i] = n;
  int val = 0, q = n;
  for (int i = 1; i <= n; i++) {
    l[a[i]] = min(l[a[i]], i);
    r[a[i]] = max(r[a[i]], i);
    val = max(val, a[i]);
    q = min(q, a[i]);
  }
  int ma = val, minn = l[val];
  lll[val] = l[val];
  for (int i = val - 1; i >= 1; i--) {
    if (r[i] == 0) {
      lll[i] = lll[i + 1];
      continue;
    }
    if (r[i] >= minn) {
      val = i + 1;
      break;
    }
    minn = min(minn, l[i]);
    lll[i] = minn;
    if (i == 1) val = 1;
  }
  long long ans = 1ll * (q) * (x - val + 2);
  int pp = val;
  int maxx = r[q];
  while (val <= ma && maxx >= lll[val]) val++;
  flag = 0;
  for (int i = q + 1; i < val; i++) {
    if (r[i] != 0) {
      if (l[i] <= maxx) {
        ans += x - val + 2;
        break;
      }
    }
    if (r[i] != 0) maxx = max(maxx, r[i]);
    ans += x - val + 2;
    while (val <= ma && maxx >= lll[val]) val++;
    if (i == val - 1) flag = 1;
  }
  if (q + 1 == val) flag = 1;
  if (flag) {
    int kk = pp;
    while (kk <= ma && lll[kk] <= maxx) kk++;
    ans += x - kk + 2;
  }
  printf("%lld\n", ans);
}
