#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
unsigned long long preLef[N], preRig[N], sum[N], a[N];
map<unsigned long long, unsigned long long> f, g;
int n, m;
unsigned long long Rand() {
  return (unsigned long long)rand() * rand() * rand() +
         (unsigned long long)rand() * rand() * rand();
}
int main() {
  srand(time(0));
  scanf("%d%d", &n, &m);
  for (int i = 0, l, r; i < n; ++i) {
    scanf("%d%d", &l, &r);
    unsigned long long t = Rand();
    a[l] ^= t;
    a[r + 1] ^= t;
    preLef[l] ^= t;
    preRig[r] ^= t;
  }
  for (int i = 1; i <= m + 1; ++i) {
    a[i] ^= a[i - 1];
    sum[i] = sum[i - 1] ^ a[i];
    preLef[i] ^= preLef[i - 1];
    preRig[i] ^= preRig[i - 1];
  }
  g[0] = 0;
  f[0] = 1;
  unsigned long long ans = 0;
  for (int i = 1; i <= m; ++i) {
    unsigned long long t = sum[i] ^ preLef[i];
    ans += f[t] * i - g[t];
    t = sum[i] ^ preRig[i];
    g[t] += i;
    ++f[t];
  }
  for (int i = 1, lf = 0; i <= m; ++i)
    if (!a[i])
      ans -= (unsigned long long)(i - lf + 1) * (i - lf) / 2;
    else
      lf = i;
  cout << ans << endl;
  return 0;
}
