#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m;
unsigned long long s1[N];
map<unsigned long long, long long> mp1, mp2;
int s2[N];
long long ans;
unsigned long long RND() {
  static unsigned long long A = 43214621742181ull;
  static unsigned long long B = 78197483241297ull;
  A ^= (A << 1) ^ (B >> 18);
  B ^= (B >> 7) ^ (A << 21);
  return A ^ B;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(1); i <= (int)(n); i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    unsigned long long tmp = RND();
    s1[l + 1] ^= tmp;
    s1[r + 1] ^= tmp;
    s2[l]++;
    s2[r + 1]--;
  }
  for (int i = (int)(1); i <= (int)(m + 1); i++) s2[i] += s2[i - 1];
  for (int i = (int)(1); i <= (int)(m + 1); i++) s1[i] ^= s1[i - 1];
  for (int i = (int)(1); i <= (int)(m + 1); i++) s1[i] ^= s1[i - 1];
  for (int i = (int)(1); i <= (int)(m); i++) {
    ++mp1[s1[i]];
    mp2[s1[i]] += i - 1;
    ans -= 1ll * mp2[s1[i]];
    ans += 1ll * mp1[s1[i]] * i;
  }
  int l = 0;
  for (int i = (int)(1); i <= (int)(m + 1); i++)
    if (i == m + 1 || s2[i]) {
      for (int j = (int)(1); j <= (int)(l); j++) ans -= 1ll * j * (l - j + 1);
      l = 0;
    } else
      ++l;
  printf("%lld\n", ans);
}
