#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int read() {
  char ch = getchar();
  int nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  int ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
unsigned long long a[200005];
map<unsigned long long, long long> b, c;
int ct[200005];
signed main() {
  int n, m;
  cin >> n >> m;
  int lmin = 0x3f3f3f3f, rmax = 0;
  for (int i = 1; i <= n; i++) {
    int l = read(), r = read();
    lmin = min(lmin, l), rmax = max(rmax, r);
    unsigned long long x = ((unsigned long long)rnd() << 32) | rnd();
    a[l + 1] ^= x, a[r + 1] ^= x;
    ct[l]++, ct[r + 1]--;
  }
  for (int i = 1; i <= m; i++) ct[i] += ct[i - 1];
  for (int i = 1; i <= m; i++) a[i] ^= a[i - 1];
  for (int i = 1; i <= m; i++) a[i] ^= a[i - 1];
  long long ans = 0;
  for (int i = 1; i <= m; i++) {
    c[a[i]]++, b[a[i]] += i - 1;
    ans += i * c[a[i]] - b[a[i]];
  }
  for (int i = 1; i <= m; i++) {
    if (ct[i]) continue;
    int r = i;
    while (r < m && !ct[r + 1]) r++;
    for (int j = 1; j <= r - i + 1; j++) ans -= 1LL * j * (j + 1) / 2;
    i = r;
  }
  cout << ans << endl;
  return 0;
}
