#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2, 3, "Ofast", "inline")
#pragma GCC target("avx,avx2")
char In[1 << 25], *ss = In, *tt = In;
inline long long read() {
  register long long x = 0, f = 1;
  register char ch =
      (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 25, stdin), ss == tt)
           ? EOF
           : *ss++);
  while (ch < '0' || ch > '9')
    f = (ch == '-') ? -1 : f,
    ch = (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 25, stdin), ss == tt)
              ? EOF
              : *ss++);
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48),
    ch = (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 25, stdin), ss == tt)
              ? EOF
              : *ss++);
  return x * f;
}
long long n, m, f[200005], vis[200005], sum[200005], ans, p;
const long long mod = 1173451;
struct node {
  long long x, y, num;
};
vector<node> ha[mod + 5];
inline long long rd() {
  return ((unsigned long long)rand() * rand() * rand() * 20041225 +
          (unsigned long long)rand() * 20041225);
}
signed main() {
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++) {
    register long long l = read(), r = read();
    f[i] = rd();
    f[i] = f[i] < 0 ? -f[i] : f[i];
    vis[l]++;
    vis[r + 1]--;
    sum[l + 1] ^= f[i];
    sum[r + 1] ^= f[i];
  }
  for (long long i = 1; i <= m; i++) vis[i] += vis[i - 1], sum[i] ^= sum[i - 1];
  for (long long i = 1; i <= m; i++) {
    p ^= sum[i];
    register long long k = p % mod, fl = 0;
    for (register long long j = 0; j < ha[k].size(); j++)
      if (ha[k][j].num == p) {
        fl = j + 1;
        break;
      }
    if (!fl)
      ha[k].push_back((node){1, i - 1, p}), fl = ha[k].size();
    else
      ha[k][fl - 1].x++, ha[k][fl - 1].y += i - 1;
    ans += i * ha[k][fl - 1].x - ha[k][fl - 1].y;
  }
  for (register long long i = 1; i <= m; i++)
    if (!vis[i]) {
      register long long r = i;
      while (r < m && !vis[r + 1]) r++;
      for (long long j = 1; j <= r - i + 1; j++) ans -= j * (r - i + 1 - j + 1);
      i = r;
    }
  printf("%lld", ans);
}
