#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e16;
const long long N = 1e6 + 5;
long long n, m, ans, S, L[N], R[N], a[N], b[N], p[N], s[N], gs[N];
map<long long, long long> mp, mp2;
struct node {
  long long l, r;
} xu[N];
inline long long read() {
  long long ret = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    ret = ret * 10 + c - 48;
    c = getchar();
  }
  if (f) return -ret;
  return ret;
}
bool cmp(node a, node b) { return a.l < b.l; }
bool cmp2(node a, node b) { return a.r > b.r; }
signed main() {
  srand(time(0));
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++) {
    L[i] = read();
    R[i] = read();
    gs[L[i]]++;
    gs[R[i] + 1]--;
    a[i] =
        (1ll * rand() * rand() * rand() * 236484161 + 1ll * rand() * 546464131);
    S ^= a[i];
    b[L[i]] ^= a[i];
    b[R[i] + 1] ^= a[i];
    p[R[i]] ^= a[i];
    s[L[i]] ^= a[i];
  }
  for (long long i = 1; i <= m + 1; i++) b[i] ^= b[i - 1];
  for (long long i = 1; i <= m + 1; i++) b[i] ^= b[i - 1];
  for (long long i = 1; i <= m + 1; i++) p[i] ^= p[i - 1];
  for (long long i = m + 1; i; i--) s[i] ^= s[i + 1];
  for (long long i = m; i; i--) {
    mp[S ^ s[i + 1] ^ b[i]] += i;
    mp2[S ^ s[i + 1] ^ b[i]]++;
    ans += mp[b[i - 1] ^ p[i - 1]] - mp2[b[i - 1] ^ p[i - 1]] * (i - 1);
  }
  for (long long i = 1; i <= m; i++) gs[i] += gs[i - 1];
  for (long long i = 1, j = 1; i <= m; i = j + 1) {
    j = i;
    if (gs[i]) continue;
    while (j + 1 <= m && gs[j + 1] == 0) j++;
    long long res = j - i + 1;
    for (long long k = 1; k <= res; k++) ans -= k * (res - k + 1);
  }
  cout << ans;
  return 0;
}
