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 N = 3e5 + 99;
int n, k, l, r, p, u, c, a[N], s[N], t[N], sz[N], tree[N], fenwik[N],
    tree_up[N], last_update[N], last[N];
vector<int> add[N], rem[N];
long long ans;
void update(int x, int val) {
  ++x;
  while (x <= N) {
    fenwik[x] += val;
    x += (x & -x);
  }
}
int query_fen(int x) {
  ++x;
  int res = 0;
  while (x > 0) {
    res += fenwik[x];
    x -= (x & -x);
  }
  return res;
}
int lower_bound(int x) {
  int l = -1, r = n, mid;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (a[mid] < x)
      l = mid;
    else
      r = mid;
  }
  return r;
}
void make() {
  for (int i = n; i < 2 * n; i++) s[i] = t[i] = i - n, sz[i] = 1;
  for (int i = n - 1; i >= 1; i--)
    s[i] = s[i * 2], t[i] = t[i * 2 + 1], sz[i] = t[i] - s[i] + 1;
}
int query_up(int l) {
  int res = 0;
  if (l > 0) res = query_fen(l - 1);
  return c - res;
}
void update_node(int x) {
  if (last[x] == c) return;
  int o = query_up(t[x]);
  if ((last_update[x] + o) % 2) tree[x] = sz[x] - tree[x];
  last_update[x] = o % 2;
  last[x] = c;
}
int query(int l, int r) {
  int res = 0;
  r++;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) {
      update_node(l);
      res += tree[l++];
    }
    if (r & 1) {
      update_node(--r);
      res += tree[r];
    }
  }
  return res;
}
void change_node(int x, int an) {
  if (x == 0) return;
  if (an < t[x]) {
    int le = an - s[x] + 1;
    update_node(x);
    tree[x] = tree[x] + le - query(s[x], an) * 2;
  }
  change_node(x / 2, an);
  if (x - n == an) {
    c++;
    update(an, 1);
  }
}
void change_interval(int l, int r) {
  c++;
  change_node(r + n, r);
  l--;
  c++;
  if (l >= 0) change_node(l + n, l);
}
void solve() {
  ans = 1ll * n * (n - 1) * (n - 2) / 6;
  change_interval(0, n - 1);
  p = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < add[i].size(); j++) change_interval(i, add[i][j]), p++;
    for (int j = 0; j < rem[i].size(); j++)
      change_interval(rem[i][j], i - 1), p++;
    u = query(0, n - 1) - (p % 2);
    ans = ans - 1ll * u * (u - 1) / 2;
    change_interval(i, i);
  }
  cout << ans;
}
int main() {
  cin >> n >> k;
  make();
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  ;
  sort(a, a + n);
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    l = lower_bound(l);
    r = lower_bound(r + 1) - 1;
    if (r >= 0) {
      add[l].push_back(r);
      rem[r + 1].push_back(l);
    }
  }
  solve();
}