#include <bits/stdc++.h>
using std::max;
using std::min;
const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3f;
std::mt19937_64 myrand(114514);
template <typename _Tp>
_Tp gcd(const _Tp &a, const _Tp &b) {
  return (!b) ? a : gcd(b, a % b);
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {
  return a >= 0 ? a : -a;
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {
  (a < b) && (a = b);
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {
  (b < a) && (a = b);
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) void read(_Tp &x) {
  char ch(getchar());
  bool f(false);
  while (!isdigit(ch)) f |= ch == 45, ch = getchar();
  x = ch & 15, ch = getchar();
  while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();
  f && (x = -x);
}
template <typename _Tp, typename... Args>
__inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {
  read(t);
  read(args...);
}
template <typename _Tp, typename... Args>
__inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b,
                                                  const Args &...args) {
  return a < b ? min(a, args...) : min(b, args...);
}
template <typename _Tp, typename... Args>
__inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b,
                                                  const Args &...args) {
  return a < b ? max(b, args...) : max(a, args...);
}
__inline__ __attribute__((always_inline)) int read_str(char *s) {
  char ch(getchar());
  while (ch == ' ' || ch == '\r' || ch == '\n') ch = getchar();
  char *tar = s;
  *tar = ch, ch = getchar();
  while (ch != ' ' && ch != '\r' && ch != '\n' && ch != EOF)
    *(++tar) = ch, ch = getchar();
  return tar - s + 1;
}
const int N = 200005;
int b[N];
struct node {
  unsigned long long a, b, c;
  __inline__ __attribute__((always_inline)) void operator^=(const node &o) {
    a ^= o.a, b ^= o.b, c ^= o.c;
  }
  __inline__ __attribute__((always_inline)) bool operator<(
      const node &o) const {
    return a == o.a ? b == o.b ? c < o.c : b < o.b : a < o.a;
  }
} a[N];
std::map<node, long long> mp1, mp2;
int main() {
  int n, m;
  read(n, m);
  int x, y;
  for (int i = 1; i <= n; ++i) {
    read(x, y);
    ++b[x], --b[y + 1];
    node val = (node){myrand(), myrand(), myrand()};
    a[x + 1] ^= val, a[y + 1] ^= val;
  }
  for (int i = 1; i <= m; ++i) a[i] ^= a[i - 1], b[i] += b[i - 1];
  for (int i = 1; i <= m; ++i) a[i] ^= a[i - 1];
  long long ans = 0;
  for (int i = 1; i <= m; ++i) {
    ++mp1[a[i]];
    mp2[a[i]] += i - 1;
    ans += 1ll * mp1[a[i]] * i - mp2[a[i]];
  }
  for (int i = 1; i <= m; ++i) {
    if (b[i]) continue;
    int j = i;
    while (j < m && !b[j + 1]) ++j;
    int len = j - i + 1;
    ans -= 1ll * len * (len + 1) * (len + 2) / 6;
    i = j;
  }
  printf("%lld\n", ans);
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

Butler Ostin wants to show Arkady that rows of odd number of fountains are beautiful, while rows of even number of fountains are not.

The butler wants to show Arkady n gardens. Each garden is a row of m cells, the i-th garden has one fountain in each of the cells between li and ri inclusive, and there are no more fountains in that garden. The issue is that some of the gardens contain even number of fountains, it is wrong to show them to Arkady.

Ostin wants to choose two integers a ≤ b and show only part of each of the gardens that starts at cell a and ends at cell b. Of course, only such segments suit Ostin that each garden has either zero or odd number of fountains on this segment. Also, it is necessary that at least one garden has at least one fountain on the segment from a to b.

Help Ostin to find the total length of all such segments, i.e. sum up the value (b - a + 1) for each suitable pair (a, b).

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of gardens and the length of each garden.

n lines follow. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ m) — the bounds of the segment that contains fountains in the i-th garden.

Output

Print one integer: the total length of all suitable segments.

Examples

Input

1 5
2 4


Output

23


Input

3 6
2 4
3 6
4 4


Output

19

Note

In the first example the following pairs suit Ostin: (a, b): (1, 2), (1, 4), (1, 5), (2, 2), (2, 4), (2, 5), (3, 3), (4, 4), (4, 5).

In the second example the following pairs suit Ostin: (a, b): (1, 2), (1, 5), (2, 2), (2, 5), (3, 3), (4, 4), (4, 6), (5, 5), (6, 6).

### Response

```cpp
#include <bits/stdc++.h>
using std::max;
using std::min;
const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3f;
std::mt19937_64 myrand(114514);
template <typename _Tp>
_Tp gcd(const _Tp &a, const _Tp &b) {
  return (!b) ? a : gcd(b, a % b);
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {
  return a >= 0 ? a : -a;
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {
  (a < b) && (a = b);
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {
  (b < a) && (a = b);
}
template <typename _Tp>
__inline__ __attribute__((always_inline)) void read(_Tp &x) {
  char ch(getchar());
  bool f(false);
  while (!isdigit(ch)) f |= ch == 45, ch = getchar();
  x = ch & 15, ch = getchar();
  while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();
  f && (x = -x);
}
template <typename _Tp, typename... Args>
__inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {
  read(t);
  read(args...);
}
template <typename _Tp, typename... Args>
__inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b,
                                                  const Args &...args) {
  return a < b ? min(a, args...) : min(b, args...);
}
template <typename _Tp, typename... Args>
__inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b,
                                                  const Args &...args) {
  return a < b ? max(b, args...) : max(a, args...);
}
__inline__ __attribute__((always_inline)) int read_str(char *s) {
  char ch(getchar());
  while (ch == ' ' || ch == '\r' || ch == '\n') ch = getchar();
  char *tar = s;
  *tar = ch, ch = getchar();
  while (ch != ' ' && ch != '\r' && ch != '\n' && ch != EOF)
    *(++tar) = ch, ch = getchar();
  return tar - s + 1;
}
const int N = 200005;
int b[N];
struct node {
  unsigned long long a, b, c;
  __inline__ __attribute__((always_inline)) void operator^=(const node &o) {
    a ^= o.a, b ^= o.b, c ^= o.c;
  }
  __inline__ __attribute__((always_inline)) bool operator<(
      const node &o) const {
    return a == o.a ? b == o.b ? c < o.c : b < o.b : a < o.a;
  }
} a[N];
std::map<node, long long> mp1, mp2;
int main() {
  int n, m;
  read(n, m);
  int x, y;
  for (int i = 1; i <= n; ++i) {
    read(x, y);
    ++b[x], --b[y + 1];
    node val = (node){myrand(), myrand(), myrand()};
    a[x + 1] ^= val, a[y + 1] ^= val;
  }
  for (int i = 1; i <= m; ++i) a[i] ^= a[i - 1], b[i] += b[i - 1];
  for (int i = 1; i <= m; ++i) a[i] ^= a[i - 1];
  long long ans = 0;
  for (int i = 1; i <= m; ++i) {
    ++mp1[a[i]];
    mp2[a[i]] += i - 1;
    ans += 1ll * mp1[a[i]] * i - mp2[a[i]];
  }
  for (int i = 1; i <= m; ++i) {
    if (b[i]) continue;
    int j = i;
    while (j < m && !b[j + 1]) ++j;
    int len = j - i + 1;
    ans -= 1ll * len * (len + 1) * (len + 2) / 6;
    i = j;
  }
  printf("%lld\n", ans);
  return 0;
}

```