#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 20, mod = 1e9 + 7;
long long n, m, l[N], r[N];
long long x[N], p[N], d[N], t[N];
map<long long, long long> cnt, sum;
long long ans;
inline long long get_random() {
  return 1ll * rand() * rand() * rand() + rand() * rand() + rand() * rand() +
         rand();
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    l[i]--;
    long long val = get_random();
    x[l[i]] ^= val;
    x[r[i]] ^= val;
    d[l[i]] ^= val;
    t[r[i]] ^= val;
  }
  for (long long i = 0; i < m; i++) {
    if (i) {
      x[i] ^= x[i - 1];
      p[i] ^= p[i - 1];
      d[i] ^= d[i - 1];
      t[i] ^= t[i - 1];
    }
    p[i] ^= x[i];
    cnt[(i ? p[i - 1] : 0) ^ t[i]]++;
    sum[(i ? p[i - 1] : 0) ^ t[i]] += i;
    ans += cnt[p[i] ^ d[i]] * (i + 1) - sum[p[i] ^ d[i]];
  }
  long long last = -1;
  for (long long i = 0; i < m; i++) {
    if (!x[i]) {
      ans -= (i - last) * (i - last + 1) / 2;
    } else
      last = i;
  }
  cout << ans << '\n';
}
