#include <bits/stdc++.h>
using namespace std;
map<unsigned long long, unsigned long long> cnt;
map<unsigned long long, unsigned long long> p;
unsigned long long ans;
int n, m;
int sig[200005];
unsigned long long ed[200005], liv[200005], s[200005];
unsigned long long Random() {
  unsigned long long ret =
      (1ull * rand() * rand() * rand() * 236484161 + 1ull * rand() * 546464131);
  return ret;
}
int main() {
  srand(time(0));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    unsigned long long tmp = Random();
    sig[x]++;
    sig[y + 1]--;
    ed[y] = ed[y] ^ tmp;
    liv[x] = liv[x] ^ tmp;
    s[x] = s[x] ^ tmp;
    s[y + 1] = s[y + 1] ^ tmp;
  }
  for (int i = 1; i <= m; i++) {
    sig[i] += sig[i - 1];
    ed[i] ^= ed[i - 1];
    liv[i] ^= liv[i - 1];
    s[i] ^= s[i - 1];
  }
  for (int i = 1; i <= m; i++) s[i] ^= s[i - 1];
  cnt[0] = 1;
  for (int i = 1; i <= m; i++) {
    ans += cnt[liv[i] ^ s[i]] * i - p[liv[i] ^ s[i]];
    cnt[ed[i] ^ s[i]]++;
    p[ed[i] ^ s[i]] += i;
  }
  int len = 0;
  for (int i = 1; i <= m; i++) {
    if (sig[i] == 0)
      len++;
    else
      len = 0;
    ans -= 1ull * len * (len + 1) / 2;
  }
  cout << ans;
  return 0;
}
