#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m;
unsigned long long a[N], b[N], sum[N], pre[N];
long long ans;
map<unsigned long long, long long> mp1, mp2;
inline int read() {
  int ret = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    ret = ret * 10 + (ch ^ 48);
    ch = getchar();
  }
  return ret * ff;
}
void write(int x) {
  if (x < 0) {
    x = -x, putchar('-');
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
void writeln(int x) { write(x), puts(""); }
void writesp(int x) { write(x), putchar(' '); }
signed main() {
  srand(time(0));
  n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    unsigned long long val = (unsigned long long)rand() * rand() * rand() +
                             (unsigned long long)rand() * rand();
    a[x] ^= val;
    a[y + 1] ^= val;
    b[x] ^= val;
  }
  for (int i = 1; i <= m; i++) {
    a[i] ^= a[i - 1];
    sum[i] = sum[i - 1] ^ a[i];
    pre[i] = pre[i - 1] ^ b[i];
  }
  for (int i = 1; i <= m; i++) {
    unsigned long long t = sum[i] ^ pre[i];
    mp1[t]++;
    mp2[t] += i - 1;
    ans += mp1[t] * i - mp2[t];
  }
  for (int i = 1, last = 0; i <= m; i++) {
    if (a[i] == 0)
      ans -= 1ll * (i - last) * (i - last + 1) / 2;
    else
      last = i;
  }
  printf("%lld", ans);
  return 0;
}
