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;
const int T = 100005;
int pos1, pos2, N, K, i, a, b, len;
int s[T], A[T], B[T];
long long ans, cur;
struct node {
  int X, Y1, Y2, check;
};
node d[2 * T];
bool cmp(node P, node Q) { return P.X < Q.X; }
struct tree {
  int l, r, sum, save;
};
tree g[T * 8];
void build(int a, int b, int u) {
  g[u] = (tree){a, b, 0, 0};
  if (a == b) return;
  int mid = (a + b) >> 1;
  build(a, mid, 2 * u);
  build(mid + 1, b, 2 * u + 1);
}
void update(int a, int b, int u) {
  if (g[u].save) {
    g[u].save = 0;
    g[u].sum = g[u].r - g[u].l + 1 - g[u].sum;
    g[2 * u].save = !g[2 * u].save;
    g[2 * u + 1].save = !g[2 * u + 1].save;
  }
  int left = g[u].l;
  int right = g[u].r;
  if (left > b || a > right) return;
  if (a <= left && right <= b) {
    g[2 * u].save = !g[2 * u].save;
    g[2 * u + 1].save = !g[2 * u + 1].save;
    g[u].sum = g[u].r - g[u].l + 1 - g[u].sum;
    return;
  }
  update(a, b, 2 * u);
  update(a, b, 2 * u + 1);
  g[u].sum = g[2 * u].sum + g[2 * u + 1].sum;
}
void doit(node V) { update(V.Y1, V.Y2, 1); }
int getsum(int a, int b, int u) {
  if (a > b) return 0;
  if (g[u].save) {
    g[u].save = 0;
    g[u].sum = g[u].r - g[u].l + 1 - g[u].sum;
    g[2 * u].save = !g[2 * u].save;
    g[2 * u + 1].save = !g[2 * u + 1].save;
  }
  int left = g[u].l;
  int right = g[u].r;
  if (left > b || a > right) return 0;
  if (a <= left && right <= b) return g[u].sum;
  int h = getsum(a, b, 2 * u) + getsum(a, b, 2 * u + 1);
  g[u].sum = g[2 * u].sum + g[2 * u + 1].sum;
  return h;
}
map<int, int> M;
int main() {
  scanf("%d %d", &N, &K);
  for (i = 1; i <= N; i++) scanf("%d", s + i);
  s[N + 1] = 1000 * 1000 * 1000 + 5;
  build(1, N, 1);
  sort(s + 1, s + N + 1);
  for (i = 1; i <= K; i++) {
    scanf("%d %d", &a, &b);
    A[i] = lower_bound(s + 1, s + N + 2, a) - s;
    B[i] = lower_bound(s + 1, s + N + 2, b) - s;
    if (s[B[i]] > b) B[i]--;
  }
  for (i = 1; i <= N; i++) s[i] = i;
  for (i = 1; i <= K; i++) {
    d[len++] = (node){A[i], A[i], B[i], 1};
    d[len++] = (node){B[i], A[i], B[i], 0};
  }
  sort(d, d + len, cmp);
  pos1 = 0;
  pos2 = 0;
  for (i = 1; i <= N; i++) {
    while (d[pos1].X <= i && pos1 < len) {
      if (d[pos1].check) doit(d[pos1]);
      pos1++;
    }
    while (d[pos2].X <= i - 1 && pos2 < len) {
      if (d[pos2].check == 0) doit(d[pos2]);
      pos2++;
    }
    cur =
        (i > 1) * (i - 1 - getsum(1, i - 1, 1)) + (i < N) * getsum(i + 1, N, 1);
    ans += (long long)cur * (cur - 1) / 2;
  }
  cout << (long long)((long long)N * (N - 1)) * (N - 2) / 6 - ans << endl;
}