#include <bits/stdc++.h>
const int N = 200005;
int n, m;
std::mt19937_64 rnd(std::time(0) + (size_t) new char);
std::map<__int128, std::pair<int, long long>> map;
__int128 preR[N], sufL[N], pre[N], all;
long long ans = 0;
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> m >> n;
  for (int i = 0; i < m; ++i) {
    __int128 v = (__int128)rnd() << 64 | rnd();
    int l, r;
    std::cin >> l >> r;
    all ^= v, preR[r] ^= v, sufL[l] ^= v;
    pre[l] ^= v, pre[r + 1] ^= v;
  }
  for (int i = 1; i <= n; ++i) pre[i] ^= pre[i - 1], preR[i] ^= preR[i - 1];
  int len = 0;
  for (int i = 1; i <= n; ++i) {
    len += !pre[i];
    if (pre[i] || i == n) {
      for (int j = 1; j <= len; ++j) ans -= (long long)j * (len - j + 1);
      len = 0;
    }
  }
  for (int i = 1; i <= n; ++i) pre[i] ^= pre[i - 1];
  for (int i = n; i >= 1; --i) sufL[i] ^= sufL[i + 1];
  for (int i = 0; i <= n; ++i) {
    auto e = map[all ^ sufL[i + 1] ^ pre[i]];
    ans += (long long)i * e.first - e.second;
    auto &q = map[pre[i] ^ preR[i]];
    ++q.first, q.second += i;
  }
  std::cout << ans << '\n';
  return 0;
}
