#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 10;
int n, m;
unsigned long long pre[N], sl[N], sr[N], all, num[N], check[N], a[N], pre2[N],
    sl2[N], sr2[N], all2;
map<unsigned long long, unsigned long long> cnt, sum;
unsigned long long rd() {
  return (unsigned long long)rand() * rand() * rand() * rand();
}
unsigned long long calc(unsigned long long x) {
  unsigned long long res = x * (x + 1) / 2 * (x + 1);
  res -= x * (x + 1) * (2 * x + 1) / 6;
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  srand(42344324);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    unsigned long long v = rd();
    int x, y;
    cin >> x >> y;
    num[x] ^= v;
    num[y + 1] ^= v;
    all ^= v;
    sl[x] ^= v;
    sr[y] ^= v;
    unsigned long long v2 = rd();
    num[x] ^= v2;
    num[y + 1] ^= v2;
    all ^= v2;
    sl[x] ^= v2;
    sr[y] ^= v2;
    check[x]++;
    check[y + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    a[i] = a[i - 1] + check[i];
  }
  for (int i = 1; i <= m; i++) num[i] = num[i - 1] ^ num[i];
  for (int i = 1; i <= m; i++) pre[i] = pre[i - 1] ^ num[i];
  for (int i = 1; i <= m + 1; i++) sr[i] = sr[i - 1] ^ sr[i];
  for (int i = m; i >= 0; i--) sl[i] = sl[i + 1] ^ sl[i];
  cnt[pre[0] ^ sr[0]] = 1;
  sum[pre[0] ^ sr[0]] = 0;
  unsigned long long ans = 0;
  for (int i = 1; i <= m; i++) {
    unsigned long long v = all ^ pre[i] ^ sl[i + 1];
    ans += cnt[v] * i;
    ans -= sum[v];
    cnt[pre[i] ^ sr[i]]++;
    sum[pre[i] ^ sr[i]] += i;
  }
  for (int l = 1, r = 1; l <= m; l = r + 1) {
    r = l;
    while (r <= m && !num[r]) r++;
    ans -= calc(r - l);
  }
  cout << ans << endl;
  return 0;
}
