#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, fl = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch - '0');
  return x * fl;
}
const int NN = 200000 + 17;
void open() {
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
}
int m, n;
int b[NN], L[NN], R[NN];
unsigned long long has[NN], a[NN], pv[NN], sv[NN], cf;
long long ans;
unsigned long long getrd() {
  return (unsigned long long)rand() * rand() * rand() * rand() +
         (unsigned long long)rand() * rand() * rand() +
         (unsigned long long)rand() * rand() + (unsigned long long)rand();
}
unordered_map<unsigned long long, long long> tax;
unordered_map<unsigned long long, long long> pos;
void ins(unsigned long long x, long long p) {
  ++tax[x];
  pos[x] += p;
}
int main() {
  m = read();
  n = read();
  for (int i = 1; i <= m; ++i) {
    int l = read(), r = read();
    has[i] = getrd();
    a[l] ^= has[i];
    a[r + 1] ^= has[i];
    pv[r] ^= has[i];
    sv[l] ^= has[i];
    cf ^= has[i];
    ++b[l];
    --b[r + 1];
  }
  for (int i = 1; i <= n; ++i) {
    a[i] ^= a[i - 1];
    b[i] += b[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    a[i] ^= a[i - 1];
    pv[i] ^= pv[i - 1];
  }
  for (int i = n; i >= 1; --i) {
    sv[i] ^= sv[i + 1];
  }
  ins(a[0] ^ pv[0], 0);
  for (int i = 1; i <= n; ++i) {
    unsigned long long sf = sv[i + 1], nf = cf ^ sf ^ a[i];
    ans += (long long)i * tax[nf] - pos[nf];
    ins(a[i] ^ pv[i], i);
  }
  int last = 0;
  for (int i = 1; i <= n; ++i) {
    if (b[i]) last = i;
    L[i] = last;
  }
  last = n + 1;
  for (int i = n; i >= 1; --i) {
    if (b[i]) last = i;
    R[i] = last;
  }
  for (int i = 1; i <= n; ++i) {
    if (!b[i]) ans -= (long long)(i - L[i]) * (R[i] - i);
  }
  printf("%lld\n", ans);
  return 0;
}
