#include <bits/stdc++.h>
using namespace std;
void qmax(int &x, int y) {
  if (x < y) x = y;
}
void qmin(int &x, int y) {
  if (x > y) x = y;
}
inline int read() {
  char s;
  int k = 0, base = 1;
  while ((s = getchar()) != '-' && s != EOF && !(isdigit(s)))
    ;
  if (s == EOF) exit(0);
  if (s == '-') base = -1, s = getchar();
  while (isdigit(s)) k = k * 10 + (s ^ '0'), s = getchar();
  return k * base;
}
inline void write(long long x) {
  static char cnt, num[20];
  cnt = 0;
  if (!x) {
    putchar('0');
    return;
  }
  for (; x; x /= 10) num[++cnt] = x % 10;
  for (; cnt; putchar(num[cnt--] + 48))
    ;
}
const int maxn = 2e5 + 100;
int n, m;
unordered_map<unsigned long long, long long> f;
unordered_map<unsigned long long, int> g;
void Srand() { srand(759405); }
unsigned long long Rand() {
  return (unsigned long long)rand() * rand() * rand() +
         (unsigned long long)rand() * rand() + rand();
}
unsigned long long val[maxn];
unsigned long long a[maxn], b[maxn], sum[maxn];
long long ans;
int main() {
  Srand();
  n = read();
  m = read();
  for (int i = 1, L, R; i <= n; i++) {
    L = read(), R = read();
    val[i] = Rand();
    a[L] ^= val[i];
    a[R + 1] ^= val[i];
    b[L] ^= val[i];
  }
  for (int i = 1; i <= m; i++) {
    a[i] ^= a[i - 1];
    b[i] ^= b[i - 1];
    sum[i] = sum[i - 1] ^ a[i];
    f[sum[i] ^ b[i]] += i - 1;
    g[sum[i] ^ b[i]]++;
    ans = ans + (long long)i * g[sum[i] ^ b[i]] - f[sum[i] ^ b[i]];
  }
  for (long long i = 1, L = 0; i <= m; i++) {
    if (!a[i]) {
      ans -= (long long)(i - L) * (i - L + 1) / 2;
    } else {
      L = i;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
