#include <bits/stdc++.h>
using namespace std;
int n, m;
unsigned long long cnt[200005], vis[200005];
unsigned long long randd() {
  return ((unsigned long long)rand() * rand() * rand() * 20200619 +
          (unsigned long long)rand() * rand() * rand() * rand() * 20200619 +
          (unsigned long long)rand() * 20200619);
}
map<unsigned long long, unsigned long long> tot, sum;
unsigned long long ans;
int main() {
  srand(time(0));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int l, r;
    unsigned long long x = randd();
    scanf("%d%d", &l, &r);
    cnt[l + 1] ^= x;
    cnt[r + 1] ^= x;
    vis[l]++;
    vis[r + 1]--;
  }
  for (int i = 1; i <= m; i++) vis[i] += vis[i - 1], cnt[i] ^= cnt[i - 1];
  for (int i = 1; i <= m; i++) cnt[i] ^= cnt[i - 1];
  for (int i = 1; i <= m; i++) {
    tot[cnt[i]]++;
    sum[cnt[i]] += i - 1;
    ans += 1ll * i * tot[cnt[i]] - sum[cnt[i]];
  }
  for (int i = 1; i <= m; i++) {
    int j = i;
    while (j <= m && !vis[j]) j++;
    for (int t = 0; t + i < j; t++) {
      ans -= 1ll * (t + 1) * (j - i - t);
    }
    i = j;
  }
  printf("%llu", ans);
  return 0;
}
