Problem: Farmer John is hosting a tennis tournament with his n cows. Each cow has a skill level si, and no two cows having the same skill level. Every cow plays every other cow exactly once in the tournament, and each cow beats every cow with skill level lower than its own.

However, Farmer John thinks the tournament will be demoralizing for the weakest cows who lose most or all of their matches, so he wants to flip some of the results. In particular, at k different instances, he will take two integers ai, bi (ai < bi) and flip all the results between cows with skill level between ai and bi inclusive. That is, for any pair x, y <image> he will change the result of the match on the final scoreboard (so if x won the match, the scoreboard will now display that y won the match, and vice versa). It is possible that Farmer John will change the result of a match multiple times. It is not guaranteed that ai and bi are equal to some cow's skill level.

Farmer John wants to determine how balanced he made the tournament results look. In particular, he wants to count the number of triples of cows (p, q, r) for which the final leaderboard shows that cow p beats cow q, cow q beats cow r, and cow r beats cow p. Help him determine this number.

Note that two triples are considered different if they do not contain the same set of cows (i.e. if there is a cow in one triple that is not in the other).

Input

On the first line are two space-separated integers, n and k (3 ≤ n ≤ 105; 0 ≤ k ≤ 105). On the next line are n space-separated distinct integers, s1, s2, ..., sn (1 ≤ si ≤ 109), denoting the skill levels of the cows. On the next k lines are two space separated integers, ai and bi (1 ≤ ai < bi ≤ 109) representing the changes Farmer John made to the scoreboard in the order he makes it.

Output

A single integer, containing the number of triples of cows (p, q, r) for which the final leaderboard shows that cow p beats cow q, cow q beats cow r, and cow r beats cow p.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3 2
1 2 3
1 2
2 3


Output

1


Input

5 3
5 9 4 1 7
1 7
2 8
3 9


Output

3

Note

In the first sample, cow 3 > cow 1, cow 3 > cow 2, and cow 2 > cow 1. However, the results between cows 1 and 2 and cows 2 and 3 are flipped, so now FJ's results show that cow 1 > cow 2, cow 2 > cow 3, and cow 3 > cow 1, so cows 1, 2, and 3 form a balanced triple. 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
} c[110000];
int a[110000], d[110000];
int sum[110000 << 2];
bool is[110000 << 2], cov[110000 << 2];
bool cmp1(const node &a, const node &b) {
  if (a.l != b.l) return a.l < b.l;
  return a.r < b.r;
}
bool cmp2(const node &a, const node &b) {
  if (a.r != b.r) return a.r > b.r;
  return a.l > b.l;
}
void Pushup(int no) { sum[no] = sum[no << 1] + sum[no << 1 | 1]; }
void Pushdown(int no, int len) {
  if (cov[no]) {
    is[no << 1] ^= 1;
    cov[no << 1] ^= 1;
    is[no << 1 | 1] ^= 1;
    cov[no << 1 | 1] ^= 1;
    sum[no << 1] = (len - (len >> 1)) - sum[no << 1];
    sum[no << 1 | 1] = (len >> 1) - sum[no << 1 | 1];
    cov[no] = 0;
  }
}
void update(int l, int r, int no, int st, int en) {
  if (st <= l && r <= en) {
    is[no] ^= 1;
    cov[no] ^= 1;
    sum[no] = r - l + 1 - sum[no];
  } else {
    int mid = l + r >> 1;
    Pushdown(no, r - l + 1);
    if (en <= mid)
      update(l, mid, no << 1, st, en);
    else if (st > mid)
      update(mid + 1, r, no << 1 | 1, st, en);
    else
      update(l, mid, no << 1, st, en), update(mid + 1, r, no << 1 | 1, st, en);
    Pushup(no);
  }
}
int query(int l, int r, int no, int st, int en) {
  if (st <= l && r <= en)
    return sum[no];
  else {
    int mid = l + r >> 1;
    Pushdown(no, r - l + 1);
    if (en <= mid)
      return query(l, mid, no << 1, st, en);
    else if (st > mid)
      return query(mid + 1, r, no << 1 | 1, st, en);
    else
      return query(l, mid, no << 1, st, en) +
             query(mid + 1, r, no << 1 | 1, st, en);
  }
}
int main() {
  int n, m, i, j, k, l, r;
  long long ans;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &c[i].l, &c[i].r);
    c[i].l = lower_bound(a + 1, a + n + 1, c[i].l) - a;
    c[i].r = upper_bound(a + 1, a + n + 1, c[i].r) - a - 1;
  }
  sort(c + 1, c + m + 1, cmp1);
  for (i = 1, j = 1; i <= m; i++) {
    while (j != n && j < c[i].l) {
      d[j] = query(1, n, 1, j + 1, n);
      j++;
    }
    if (c[i].l <= c[i].r) update(1, n, 1, c[i].l, c[i].r);
  }
  while (j != n) {
    d[j] = query(1, n, 1, j + 1, n);
    j++;
  }
  memset(is, 0, sizeof(is));
  memset(sum, 0, sizeof(sum));
  memset(cov, 0, sizeof(cov));
  sort(c + 1, c + m + 1, cmp2);
  for (i = 1, j = n; i <= m; i++) {
    while (j != 1 && j > c[i].r) {
      d[j] += j - 1 - query(1, n, 1, 1, j - 1);
      j--;
    }
    if (c[i].l <= c[i].r) update(1, n, 1, c[i].l, c[i].r);
  }
  while (j != 1) {
    d[j] += j - 1 - query(1, n, 1, 1, j - 1);
    j--;
  }
  for (i = 1, ans = (long long)n * (n - 1) * (n - 2) / 6; i <= n; i++) {
    ans -= (long long)d[i] * (d[i] - 1) / 2;
  }
  printf("%I64d\n", ans);
  return 0;
}