#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    ;
  int x = ch - '0';
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    x = x * 10 + ch - '0';
  return x;
}
const int N = 2 * 1e5 + 5;
int n, m, l, r, num[N];
long long pre_1[N], sl_1[N], sr_1[N], all_1, pre_2[N], sl_2[N], sr_2[N], all_2;
map<long long, long long> cnt, sum;
long long ans;
long long calc(int x) {
  long long res = (long long)x * (x + 1) / 2 * (x + 1);
  res -= (long long)x * (x + 1) * (2 * x + 1) / 6;
  return res;
}
int main() {
  n = read();
  m = read();
  srand(20180316);
  for (int i = 1; i <= n; i++) {
    l = read();
    r = read();
    long long key_1 = (long long)rand() * rand() * rand() * rand();
    pre_1[l] ^= key_1;
    pre_1[r + 1] ^= key_1;
    sl_1[r] ^= key_1;
    sr_1[l] ^= key_1;
    all_1 ^= key_1;
    long long key_2 = (long long)rand() * rand() * rand() * rand();
    pre_2[l] ^= key_2;
    pre_2[r + 1] ^= key_2;
    sl_2[r] ^= key_2;
    sr_2[l] ^= key_2;
    all_2 ^= key_2;
    num[l]++;
    num[r + 1]--;
  }
  for (int i = 1; i <= m; i++) num[i] += num[i - 1];
  for (int i = 1; i <= m; i++)
    pre_1[i] ^= pre_1[i - 1], pre_2[i] ^= pre_2[i - 1];
  for (int i = 1; i <= m; i++)
    pre_1[i] ^= pre_1[i - 1], pre_2[i] ^= pre_2[i - 1];
  for (int i = 1; i <= m; i++) sr_1[i] ^= sr_1[i - 1], sr_2[i] ^= sr_2[i - 1];
  for (int i = m; i >= 1; i--) sl_1[i] ^= sl_1[i + 1], sl_2[i] ^= sl_2[i + 1];
  cnt[sl_1[1] ^ sl_2[1]]++;
  for (int i = 1; i <= m; i++) {
    long long now = all_1 ^ pre_1[i] ^ sr_1[i] ^ all_2 ^ pre_2[i] ^ sr_2[i];
    ans += (long long)i * cnt[now];
    ans -= sum[now];
    cnt[pre_1[i] ^ sl_1[i + 1] ^ pre_2[i] ^ sl_2[i + 1]]++;
    sum[pre_1[i] ^ sl_1[i + 1] ^ pre_2[i] ^ sl_2[i + 1]] += i;
  }
  for (int l = 1, r = 1; l <= m; l = r + 1) {
    r = l;
    while (r <= m && !num[r]) r++;
    ans -= calc(r - l);
  }
  printf("%I64d\n", ans);
  return 0;
}
