#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m;
map<unsigned long long, unsigned long long> mp, c;
long long ans;
unsigned long long a[maxn], s[maxn], A[maxn], sum[maxn];
unsigned long long R() {
  return (unsigned long long)rand() * rand() * rand() +
         (unsigned long long)rand();
}
int main() {
  srand(998244353);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    unsigned long long t = R();
    a[l] ^= t;
    a[r + 1] ^= t;
    A[l] ^= t;
    ++sum[l];
    --sum[r + 1];
  }
  for (int i = 1; i <= m; ++i) {
    a[i] ^= a[i - 1];
    s[i] = s[i - 1] ^ a[i];
    A[i] ^= A[i - 1];
    sum[i] += sum[i - 1];
  }
  for (int i = 1; i <= m; ++i) {
    ++mp[s[i] ^ A[i]];
    c[s[i] ^ A[i]] += i - 1;
    ans += mp[s[i] ^ A[i]] * i - c[s[i] ^ A[i]];
  }
  int cnt = 0;
  for (int i = 1, j = 0; i <= m; ++i)
    if (a[i] == 0)
      ans -= 1LL * (i - j) * (i - j + 1) / 2;
    else
      j = i;
  printf("%lld\n", ans);
  return 0;
}
