#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n, m;
unsigned long long A[MAXN], B[MAXN], S, rest;
unsigned long long ans;
pair<int, int> s[MAXN];
map<unsigned long long, unsigned long long> sum, cnt;
int main() {
  scanf("%d %d", &m, &n);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d %d", &x, &y);
    s[i] = make_pair(x, y);
    unsigned long long val =
        (((unsigned long long)rand() << 15 | rand()) << 15 | rand()) << 15 |
        rand();
    B[x] ^= val, A[y + 1] ^= val;
  }
  cnt[0] = 1;
  unsigned long long start = 0, end = 0;
  for (int i = 1; i <= n; i++) {
    S ^= (rest ^= A[i] ^ B[i]);
    start ^= A[i + 1], end ^= B[i];
    ans += i * cnt[S ^ end] - sum[S ^ end];
    cnt[S ^ start]++, sum[S ^ start] += i;
  }
  s[++m] = make_pair(n + 1, n + 1);
  sort(s + 1, s + m + 1);
  for (int i = 1, j = 0; i <= m; j = max(j, s[i++].second))
    if (s[i].first > j)
      for (int p = j + 1; p < s[i].first; p++)
        ans -= 1ll * (p - j) * (s[i].first - p);
  cout << ans;
  return 0;
}
