#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200005;
mt19937_64 e;
inline ll randint() {
  static uniform_int_distribution<ll> u;
  return u(e);
}
int n, m;
ll ans, pvis[N], pre[N], a[N];
map<ll, ll> f, g;
int main() {
  ios::sync_with_stdio(false);
  e.seed(time(0));
  cin >> n >> m;
  int t1, t2;
  for (int i = 1; i <= n; i++) {
    ll v = randint();
    cin >> t1 >> t2;
    pvis[t1] ^= v;
    a[t1] ^= v;
    a[t2 + 1] ^= v;
  }
  for (int i = 1; i <= m; i++)
    a[i] ^= a[i - 1], pvis[i] ^= pvis[i - 1], pre[i] = pre[i - 1] ^ a[i];
  for (int i = 1; i <= m; i++) {
    ll tt = pre[i] ^ pvis[i];
    f[tt] += i - 1;
    ++g[tt];
    ans += g[tt] * i - f[tt];
  }
  for (int i = 1, l = 0; i <= m; i++)
    if (!a[i])
      ans -= (i - l + 1ll) * (i - l) / 2;
    else
      l = i;
  cout << ans << endl;
  return 0;
}
