#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, m;
unsigned long long a[maxn], A[maxn], s[maxn], d[maxn], ans;
map<unsigned long long, unsigned long long> num, sum;
int main() {
  srand(998244353);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    unsigned long long w = (unsigned long long)rand() * rand() * rand() +
                           (unsigned long long)rand() * rand() + rand();
    a[x] ^= w;
    a[y + 1] ^= w;
    A[x] ^= w;
  }
  for (int i = 1; i <= m; i++)
    a[i] ^= a[i - 1], s[i] = s[i - 1] ^ a[i], d[i] = d[i - 1] ^ A[i];
  for (int i = 1; i <= m; i++) {
    unsigned long long w = s[i] ^ d[i];
    num[w]++;
    sum[w] += i - 1;
    ans += num[w] * i - sum[w];
  }
  for (int i = 1, j = 0; i <= m; i++)
    if (a[i] == 0)
      ans -=
          (((unsigned long long)i - j) * (((unsigned long long)i - j) + 1) / 2);
    else
      j = i;
  printf("%I64d", ans);
  return 0;
}
