#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int inf = 0x3f3f3f3f;
int n, m;
map<unsigned long long, unsigned long long> cnt, sum;
unsigned long long ans = 0, cnt1[200005], cnt2[200005], sum1[200005],
                   sum2[200005];
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  if (p1 == p2) {
    p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);
    if (p1 == p2) return EOF;
  }
  return *p1++;
}
inline void read(int &x) {
  char c = getchar();
  int b = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') b = -1;
  for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar())
    ;
  x = x * b;
}
inline void read(long long &x) {
  char c = getchar();
  int b = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') b = -1;
  for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar())
    ;
  x = x * b;
}
int main(int argc, char *argv[]) {
  srand((unsigned)time(NULL));
  read(n);
  read(m);
  for (int i = (1); i <= (n); i++) {
    int l, r;
    read(l);
    read(r);
    unsigned long long kidding = (unsigned long long)rand() * rand() * rand() +
                                 (unsigned long long)rand() * rand() + rand();
    cnt1[l] ^= kidding, cnt1[r + 1] ^= kidding, cnt2[l] ^= kidding;
  }
  for (int i = (1); i <= (m); i++)
    cnt1[i] ^= cnt1[i - 1], sum1[i] = sum1[i - 1] ^ cnt1[i],
                            sum2[i] = sum2[i - 1] ^ cnt2[i];
  for (int i = (1); i <= (m); i++) {
    unsigned long long tmp = sum1[i] ^ sum2[i];
    cnt[tmp]++;
    sum[tmp] += i - 1;
    ans += 1ll * i * cnt[tmp] - sum[tmp];
  }
  int pos = 0;
  for (int i = (1); i <= (m); i++)
    if (cnt1[i] == 0)
      ans -= (1ll * (i - pos) * (i - pos + 1) / 2);
    else
      pos = i;
  cout << ans << endl;
  return 0;
}
