#include <bits/stdc++.h>
using namespace std;
int p[200200];
unsigned long long h[200200];
vector<int> st[200200], ed[200200];
map<unsigned long long, unsigned long long> cnt, sum;
unsigned long long myrand() {
  return ((unsigned long long)rand() << 50) +
         ((unsigned long long)rand() << 35) +
         ((unsigned long long)rand() << 20) +
         ((unsigned long long)rand() << 10) + rand();
}
int main() {
  int n, m;
  cin >> n >> m;
  unsigned long long all = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--;
    p[l]++;
    p[r]--;
    st[l].push_back(i);
    ed[r].push_back(i);
    all ^= (h[i] = myrand());
  }
  unsigned long long cur = 0, rem = 0, ans = 0;
  for (int i = 0; i <= m; i++) {
    for (int first : ed[i]) rem ^= h[first];
    ans += cnt[cur] * i - sum[cur];
    cur ^= rem;
    cnt[cur]++;
    sum[cur] += i;
    for (int first : st[i]) rem ^= h[first];
  }
  for (int i = 0, s = 0, c = 0; i < m; i++) {
    s += p[i];
    if (s == 0) {
      c++;
      ans -= (unsigned long long)c * (c + 1) / 2;
    } else
      c = 0;
  }
  cout << ans << endl;
  return 0;
}
