#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, x;
  cin >> n >> x;
  vector<long long> a(n);
  for (auto &t : a) {
    cin >> t;
    t--;
  }
  vector<vector<long long>> pos(x);
  for (long long i = 0; i < n; i++) {
    pos[a[i]].push_back(i);
  }
  long long pr = 0;
  long long sf = x - 1;
  {
    long long mx = -1;
    for (long long i = 0; i < x; i++) {
      if (pos[i].empty()) {
        pr = i;
      } else if (mx < pos[i].front()) {
        pr = i;
        mx = pos[i].back();
      } else {
        break;
      }
    }
  }
  {
    long long mn = n;
    for (long long i = x - 1; i >= 0; i--) {
      if (pos[i].empty()) {
        sf = i;
      } else if (pos[i].back() < mn) {
        sf = i;
        mn = pos[i].front();
      } else {
        break;
      }
    }
  }
  if (false) cerr << "pr " << pr << " sf " << sf << endl;
  vector<long long> prefmax(n);
  prefmax[0] = a[0];
  for (long long i = 1; i < n; i++) {
    prefmax[i] = max(prefmax[i - 1], a[i]);
  }
  long long max_pos = -1;
  if (false)
    cerr << "c1 " << min(x, ((pr + 1) - 0 + 1)) << " c2 "
         << min(x, ((x - 1) - (sf - 1) + 1)) << endl;
  long long ans =
      min(x, ((pr + 1) - 0 + 1)) + min(x, ((x - 1) - (sf - 1) + 1)) - 1;
  if (false) cerr << "start ans " << ans << endl;
  for (long long i = 0; i <= pr; i++) {
    if (!pos[i].empty()) {
      max_pos = max(max_pos, pos[i].back());
    }
    long long minr = -1;
    if (max_pos != -1) {
      if (false) cerr << "uu " << max_pos << endl;
      minr = prefmax[max_pos];
    }
    minr = max(minr, sf - 1);
    minr = max(minr, i + 1);
    long long cnt = (x - minr - 1);
    if (false) cerr << "cnt " << cnt << endl;
    ans += max((long long)0, cnt);
  }
  cout << ans << endl;
}
