#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
inline unsigned long long R() {
  static unsigned long long seed = time(0);
  return seed ^= seed >> 25, seed ^= seed << 39, seed ^= seed >> 30,
         seed ^= seed << 35;
}
map<unsigned long long, pair<int, unsigned long long> > s;
map<unsigned long long, pair<int, unsigned long long> >::iterator it;
int n, m, a[N], i, l, r;
vector<unsigned long long> v[N];
unsigned long long b[N], x, ans;
pair<int, unsigned long long>* z;
int main() {
  cin.tie(0), cin.sync_with_stdio(0);
  cin >> n >> m;
  for (i = 1; i <= n; ++i) {
    cin >> l >> r;
    x = R();
    b[l] ^= x, b[r + 1] ^= x;
    v[r].push_back(x);
    ++a[l], --a[r + 1];
  }
  for (i = 1, x = 0, s[l = 0] = make_pair(1, 0); i <= m; ++i) {
    x ^= b[i] ^= b[i - 1];
    it = s.find(x ^ b[i]);
    if (it != s.end()) ans += 1ll * i * it->second.first - it->second.second;
    if (!(a[i] += a[i - 1]))
      ++l;
    else
      ans -= (1ll * l * (l + 1) * (l << 1 | 1) + 3ll * l * (l + 1)) / 12, l = 0;
    for (int j = 0; j < int(v[i].size()); ++j) x ^= v[i][j];
    z = &s[x];
    z->first++, z->second += i;
  }
  ans -= (1ll * l * (l + 1) * (l << 1 | 1) + 3ll * l * (l + 1)) / 12;
  cout << ans << endl;
  return 0;
}
