#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, x, y, dlt[N];
pair<unsigned long long, unsigned long long> sum[N], val[N];
unsigned long long ans;
pair<unsigned long long, unsigned long long> tot;
vector<int> v[N];
map<pair<unsigned long long, unsigned long long>, unsigned long long> G, D;
class FileInputOutput {
 private:
  char Fin[1 << 21], *A, *B;

 public:
  FileInputOutput() { A = B = Fin; }
  inline void read(int &x) {
    x = 0;
    char ch;
    while (!isdigit(
        ch = (A == B && (B = (A = Fin) + fread(Fin, 1, 1 << 21, stdin), A == B)
                  ? EOF
                  : *A++)))
      ;
    while (
        x = (x << 3) + (x << 1) + (ch & 15),
        isdigit(ch = (A == B && (B = (A = Fin) + fread(Fin, 1, 1 << 21, stdin),
                                 A == B)
                          ? EOF
                          : *A++)))
      ;
  }
} F;
inline pair<unsigned long long, unsigned long long> operator^(
    pair<unsigned long long, unsigned long long> A,
    pair<unsigned long long, unsigned long long> B) {
  return pair<unsigned long long, unsigned long long>(A.first ^ B.first,
                                                      A.second ^ B.second);
}
inline unsigned long long Rand(void) { return 1ULL * rand() * rand() * rand(); }
inline unsigned long long calc(int x) {
  return 1ULL * x * (x + 1) * (x + 2) / 6;
}
int main() {
  register int i, j;
  for (srand(time(0)), F.read(n), F.read(m), i = 1; i <= n; ++i) {
    F.read(x);
    F.read(y);
    val[i] = make_pair(Rand(), Rand());
    v[x].push_back(i);
    ++dlt[x];
    --dlt[y + 1];
    sum[x] = sum[x] ^ val[i];
    sum[y + 1] = sum[y + 1] ^ val[i];
  }
  for (i = 1; i <= m; ++i) sum[i] = sum[i - 1] ^ sum[i], dlt[i] += dlt[i - 1];
  for (tot = make_pair(0, 0), i = 1; i <= m; ++i) {
    tot = tot ^ sum[i];
    int lim = v[i].size();
    for (j = 0; j < lim; ++j) tot = tot ^ val[v[i][j]];
    ++G[tot];
    D[tot] += i - 1;
    ans += 1ULL * G[tot] * i - D[tot];
  }
  for (i = 1; i <= m; ++i)
    if (!dlt[i]) {
      j = i;
      while (j < m && !dlt[j + 1]) ++j;
      ans -= calc(j - i + 1);
      i = j;
    }
  return printf("%lld", ans), 0;
}
