#include <bits/stdc++.h>
using namespace std;
int a[2000005], l[2000005], r[2000005], L[2000005], R[2000005];
bool ldp[2000005], rdp[2000005];
int BIT[2000005];
void update(int indx, int val) {
  indx++;
  while (indx < 2000005) {
    BIT[indx] += val;
    indx += (indx & -indx);
  }
}
int sum(int indx) {
  indx++;
  int ans = 0;
  while (indx != 0) {
    ans += BIT[indx];
    indx -= (indx & -indx);
  }
  return ans;
}
int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  for (int i = 1; i <= x; i++) l[i] = n + 1, r[i] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    l[a[i]] = min(l[a[i]], i);
    r[a[i]] = max(r[a[i]], i);
  }
  int Max = 0;
  for (int i = 1; i <= x; i++) {
    if (l[i] >= Max)
      ldp[i] = 1;
    else
      break;
    Max = max(Max, r[i]);
    R[i] = Max;
  }
  int Min = n + 1;
  for (int i = x; i >= 1; i--) {
    if (r[i] <= Min)
      rdp[i] = 1;
    else
      break;
    Min = min(Min, l[i]);
    L[i] = Min;
  }
  long long int Ans = 0;
  for (int i = 1; i <= x - 1; i++)
    if (ldp[i]) update(R[i], 1);
  for (int j = x; j >= 1; j--) {
    if (ldp[j - 1]) update(R[j - 1], -1);
    if (rdp[j]) Ans += sum(L[j]);
  }
  for (int i = 1; i < x; i++)
    if (ldp[i]) Ans++;
  for (int i = 2; i <= x; i++)
    if (rdp[i]) Ans++;
  cout << Ans + 1 << endl;
}
