#include <bits/stdc++.h>
using namespace std;
const int maxn = 200006;
int n, m;
unsigned long long ans, a[maxn], sum[maxn], D[maxn];
map<unsigned long long, unsigned long long> f, g;
unsigned long long Rand() {
  return (unsigned long long)rand() * rand() * rand() +
         (unsigned long long)rand() * rand() + rand();
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, l, r; i <= n; i++) {
    unsigned long long t = Rand();
    scanf("%d%d", &l, &r);
    a[l] ^= t;
    a[r + 1] ^= t;
    D[l] ^= t;
  }
  for (int i = 1; i <= m; i++)
    a[i] ^= a[i - 1], D[i] ^= D[i - 1], sum[i] = sum[i - 1] ^ a[i];
  for (int i = 1; i <= m; i++) {
    unsigned long long t = sum[i] ^ D[i];
    f[t] += i - 1;
    g[t]++;
    ans += g[t] * i - f[t];
  }
  for (int i = 1, L = 0; i <= m; i++)
    if (!a[i])
      ans -= (unsigned long long)(i - L + 1) * (i - L) / 2;
    else
      L = i;
  return printf("%lld", ans), 0;
}
