#include <bits/stdc++.h>
using namespace std;
int i, i0, n, m, a[1000005], d[1000005];
bool f[1000005], f0[1000005];
int main() {
  scanf("%d %d", &n, &m);
  int mx = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (mx > a[i]) f0[a[i]] = 1;
    mx = max(mx, a[i]);
    d[a[i]] = max({d[a[i]], mx, a[i] + 1});
  }
  for (i = n; i; i--) {
    mx = min(mx, a[i]);
    if (mx < a[i]) f[a[i]] = 1;
  }
  long long ans = 0;
  int lim = m;
  while (lim > 1 && !f0[lim]) lim--;
  for (i = 1; i <= m; i++) {
    ans += m - lim + 1;
    lim = max({lim, d[i], i + 1});
    if (f[i]) break;
  }
  printf("%lld\n", ans);
  return 0;
}
