#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, m;
unsigned long long res;
map<unsigned long long, pair<unsigned long long, unsigned long long> > mp;
unsigned long long rnd() {
  return (unsigned long long)RAND_MAX * RAND_MAX * RAND_MAX * rand() +
         (unsigned long long)RAND_MAX * RAND_MAX * rand() +
         (unsigned long long)RAND_MAX * rand() + (unsigned long long)rand();
}
unsigned long long a[1000005], c[1000005];
int b[1000005];
signed main() {
  srand(233);
  m = read(), n = read();
  for (register int i = (1); i <= (m); ++i) {
    int l = read(), r = read();
    unsigned long long val = rnd();
    a[l + 1] ^= val, a[r + 1] ^= val, b[l]++, b[r + 1]--;
  }
  for (register int i = (1); i <= (n); ++i) a[i] ^= a[i - 1], b[i] += b[i - 1];
  for (register int i = (1); i <= (n); ++i) a[i] ^= a[i - 1];
  for (register int i = (1); i <= (n); ++i) {
    pair<unsigned long long, unsigned long long> t = mp[a[i]];
    t.first++, t.second += i - 1, res += t.first * i - t.second;
    mp[a[i]] = t;
  }
  unsigned long long len = 0;
  for (register int i = (1); i <= (n); ++i) {
    if (!b[i])
      len++;
    else
      len = 0;
    res -= len * (len + 1) / 2;
  }
  cout << res;
  return 0;
}
