#include <bits/stdc++.h>
using namespace std;
long long calc(long long x) {
  return (x + 1) * (x) * ((x) + 1) / 2 - x * (x + 1) * (2 * x + 1) / 6;
}
inline long long getint() {
  long long w = 0, q = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') q = 1, c = getchar();
  while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar();
  return q ? -w : w;
}
long long r() { return (rand() << 15) | rand(); }
long long R() { return ((long long)(r()) << 30) | r(); }
vector<long long> A[1010000], B[1010000];
long long a[1010000], b[1010000], n, m, ans;
long long S, T;
map<long long, long long> F, val;
int main() {
  srand(time(NULL));
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) a[i] = R();
  for (long long i = 1; i <= n; i++) {
    long long l = getint(), r = getint();
    A[l].push_back(i);
    B[r].push_back(i);
    b[l] ^= a[i], b[r + 1] ^= a[i];
  }
  for (long long i = 1; i <= m; i++) b[i] ^= b[i - 1];
  for (long long i = 1; i <= m; i++) b[i] ^= b[i - 1];
  val[0]++;
  for (long long i = 1; i <= m; i++) {
    long long w = A[i].size();
    for (long long j = 0; j < w; j++) S ^= a[A[i][j]];
    ans += val[S ^ b[i]] * i - F[S ^ b[i]];
    w = B[i].size();
    for (long long j = 0; j < w; j++) T ^= a[B[i][j]];
    F[b[i] ^ T] += i;
    val[b[i] ^ T]++;
  }
  for (long long i = m; i; i--) b[i] ^= b[i - 1];
  b[m + 1] = -1;
  long long l = 0;
  for (long long i = 1; i <= m + 1; i++)
    if (b[i] != 0) ans -= calc((i - l - 1)), l = i;
  cout << ans;
  return 0;
}
