#include <bits/stdc++.h>
using namespace std;
int n, m;
long long ans;
int l[200010], r[200010], num[200010];
unsigned long long p1[200010], p2[200010];
vector<unsigned long long> s1[200010], t1[200010], s2[200010], t2[200010];
map<pair<unsigned long long, unsigned long long>, long long> mp, s;
inline long long calc(int x) {
  return 1ll * (x + 1) * x * x / 2 - 1ll * (x - 1) * x / 2 -
         1ll * x * (x - 1) * (2 * x - 1) / 6;
}
int main() {
  scanf("%d%d", &n, &m);
  srand(1098409);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &l[i], &r[i]);
    unsigned long long hash1 = 1ULL * rand() * rand() * rand(),
                       hash2 = 1ULL * rand() * rand() * rand();
    s1[l[i]].push_back(hash1);
    s2[l[i]].push_back(hash2);
    t1[r[i]].push_back(hash1);
    t2[r[i]].push_back(hash2);
    p1[l[i]] ^= hash1;
    p1[r[i] + 1] ^= hash1;
    p2[l[i]] ^= hash2;
    p2[r[i] + 1] ^= hash2;
    num[l[i]]++;
    num[r[i] + 1]--;
  }
  for (int i = 1; i <= m; i++) p1[i] ^= p1[i - 1], p2[i] ^= p2[i - 1];
  for (int i = 1; i <= m; i++) p1[i] ^= p1[i - 1], p2[i] ^= p2[i - 1];
  unsigned long long a1 = 0, b1 = 0, a2 = 0, b2 = 0;
  mp[pair<unsigned long long, unsigned long long>(0, 0)] = 1;
  for (int i = 1; i <= m; i++) {
    for (int x = 0; x < s1[i].size(); x++) a1 ^= s1[i][x], a2 ^= s2[i][x];
    ans +=
        mp[pair<unsigned long long, unsigned long long>(a1 ^ p1[i],
                                                        a2 ^ p2[i])] *
            i -
        s[pair<unsigned long long, unsigned long long>(a1 ^ p1[i], a2 ^ p2[i])];
    for (int x = 0; x < t1[i].size(); x++) b1 ^= t1[i][x], b2 ^= t2[i][x];
    mp[pair<unsigned long long, unsigned long long>(b1 ^ p1[i], b2 ^ p2[i])]++;
    s[pair<unsigned long long, unsigned long long>(b1 ^ p1[i], b2 ^ p2[i])] +=
        i;
  }
  for (int i = 1; i <= m; i++) num[i] += num[i - 1];
  for (int i = 1, j; i <= m; i = j + 1) {
    j = i;
    while (j <= m && num[j] == 0) j++;
    j--;
    if (j < i)
      j = i;
    else
      ans = ans - calc(j - i + 1);
  }
  printf("%lld\n", ans);
  return 0;
}
