#include <bits/stdc++.h>
using namespace std;
int ar[1000021][2] = {}, n, k, lf, rg, ps;
long long rs = 0, x, l, r;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    if (ar[k][0] == 0) {
      ar[k][0] = i;
    }
    ar[k][1] = i;
  }
  l = 1;
  r = x;
  while (!ar[l][1]) {
    l++;
  }
  while (!ar[r][0]) {
    r--;
  }
  lf = ar[l][1];
  rg = ar[r][0];
  ar[x + 1][0] = -1;
  ar[x + 1][1] = -1;
  ar[0][0] = 1e9;
  ar[0][1] = 1e9;
  for (; l <= x; l++) {
    if (ar[l + 1][0]) {
      if (ar[l + 1][0] < lf) {
        break;
      }
      lf = ar[l + 1][1];
    }
  }
  for (; r > 0; r--) {
    if (ar[r - 1][1]) {
      if (rg < ar[r - 1][1]) {
        break;
      }
      rg = ar[r - 1][0];
    }
  }
  lf = 0;
  ar[0][1] = 0;
  for (int i = r; i <= x; i++) {
    if (ar[i][0]) {
      rg = ar[i][0];
      ps = i;
      break;
    }
  }
  for (int i = 0; i <= l; i++) {
    if (ar[i][1]) {
      lf = ar[i][1];
    }
    while (lf > rg && r <= x) {
      r = ps + 1;
      for (int i = r; i <= x; i++) {
        if (ar[i][0]) {
          rg = ar[i][0];
          ps = i;
          break;
        } else if (i == x) {
          rg = 1e9;
          ps = i + 1;
        }
      }
    }
    if (r < i + 2) {
      r = i + 2;
    }
    rs += x - r + 2;
  }
  cout << rs << "\n";
  return 0;
}
