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 sum;
  int qu;
  int bq;
  node *l, *r;
  node() {
    qu = sum = bq = 0;
    l = r = NULL;
  }
  void getnot(int b, int e, int p, int q) {
    if (b == e) return;
    if (b == p && e == q) {
      bq = true;
      qu = !qu;
      sum = q - p - sum;
      return;
    }
    int mid = (p + q) / 2;
    if (!l) {
      l = new node;
      r = new node;
    }
    if (bq && qu) {
      l->getnot(p, mid, p, mid);
      r->getnot(mid, q, mid, q);
    }
    bq = qu = 0;
    if (e <= mid)
      l->getnot(b, e, p, mid);
    else if (b >= mid)
      r->getnot(b, e, mid, q);
    else {
      l->getnot(b, mid, p, mid);
      r->getnot(mid, e, mid, q);
    }
    sum = l->sum + r->sum;
  }
  int getsum(int b, int e, int p, int q) {
    if (b == e) return 0;
    if (b == p && e == q) return sum;
    int mid = (p + q) / 2;
    if (!l) {
      l = new node;
      r = new node;
    }
    if (bq && qu) {
      l->getnot(p, mid, p, mid);
      r->getnot(mid, q, mid, q);
    }
    bq = qu = 0;
    if (e <= mid) return l->getsum(b, e, p, mid);
    if (b >= mid) return r->getsum(b, e, mid, q);
    return l->getsum(b, mid, p, mid) + r->getsum(mid, e, mid, q);
  }
} root;
const int maxn = 100 * 1000 + 100;
long long n, k;
vector<int> ql, qr, qh;
vector<int> s;
vector<int> qo;
int p[maxn];
long long d[maxn];
bool cmp(int a, int b) { return s[a] < s[b]; }
bool cmpq(int a, int b) { return qh[a] < qh[b]; }
int gl(int x) {
  s[n] = x;
  return lower_bound(p, p + n, n, cmp) - p;
}
int gu(int x) {
  s[n] = x;
  return upper_bound(p, p + n, n, cmp) - p;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  int t1, t2;
  for (int i = 0; i < n; ++i) {
    cin >> t1;
    s.push_back(t1);
    p[i] = i;
  }
  s.push_back(0);
  sort(p, p + n, cmp);
  for (int i = 0; i < k; ++i) {
    cin >> t1 >> t2;
    int conv1, conv2;
    conv1 = gl(t1);
    conv2 = gu(t2);
    ql.push_back(conv1);
    qr.push_back(conv2);
    qo.push_back((int)(qh).size());
    qh.push_back(conv1);
    ql.push_back(conv1);
    qr.push_back(conv2);
    qo.push_back((int)(qh).size());
    qh.push_back(conv2);
  }
  sort((qo).begin(), (qo).end(), cmpq);
  int j = 0;
  for (int i = 0; i < n; ++i) {
    while (j < (int)(qh).size() && qh[qo[j]] <= i) {
      int l = ql[qo[j]];
      int r = qr[qo[j]];
      root.getnot(l, r, 0, n);
      j++;
    }
    d[i] =
        root.getsum(0, i, 0, n) + (n - (i + 1) - root.getsum(i + 1, n, 0, n));
  }
  long long ans = n * (n - 1ll) * (n - 2ll) / 6ll;
  for (int i = 0; i < n; ++i) ans -= d[i] * (d[i] - 1) / 2ll;
  cout << ans << endl;
  return 0;
}