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;
using ll = long long;
const int N = 1e5L + 11;
int a[N], b[N];
struct SegTree {
  bool f[N * 8];
  int v[N * 4][2];
  void build(int l, int r, int x = 1) {
    f[x] = v[x][1] = 0;
    v[x][0] = r - l;
    if (l + 1 != r) {
      build(l, (l + r) / 2, 2 * x);
      build((l + r) / 2, r, 2 * x + 1);
    }
  }
  void push(int x) {
    if (f[x]) swap(v[x][0], v[x][1]);
    f[2 * x] ^= f[x];
    f[2 * x + 1] ^= f[x];
    f[x] = 0;
  }
  void change(int l, int r, int ql, int qr, int x = 1) {
    push(x);
    if (ql == l && qr == r)
      f[x] = 1;
    else {
      if (qr <= (l + r) / 2)
        change(l, (l + r) / 2, ql, qr, 2 * x);
      else if (ql >= (l + r) / 2)
        change((l + r) / 2, r, ql, qr, 2 * x + 1);
      else {
        change(l, (l + r) / 2, ql, (l + r) / 2, 2 * x);
        change((l + r) / 2, r, (l + r) / 2, qr, 2 * x + 1);
      }
      push(2 * x);
      push(2 * x + 1);
      v[x][0] = v[2 * x][0] + v[2 * x + 1][0];
      v[x][1] = v[2 * x][1] + v[2 * x + 1][1];
    }
  }
  int query(int l, int r, int ql, int qr, int x = 1) {
    push(x);
    if (ql == l && qr == r) return v[x][0];
    if (qr <= (l + r) / 2) return query(l, (l + r) / 2, ql, qr, 2 * x);
    if (ql >= (l + r) / 2) return query((l + r) / 2, r, ql, qr, 2 * x + 1);
    return query(l, (l + r) / 2, ql, (l + r) / 2, 2 * x) +
           query((l + r) / 2, r, (l + r) / 2, qr, 2 * x + 1);
  }
} st;
vector<int> eves[N];
int c[2][N];
int main() {
  ios ::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  mp[0] = mp[(int)2e9L] = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    mp[x] = 0;
  }
  {
    int c = 0;
    for (auto &i : mp) i.second = c++;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    a[i] = mp.lower_bound(a[i])->second;
    b[i] = (--mp.upper_bound(b[i]))->second;
    if (a[i] > b[i]) {
      i--;
      m--;
    }
  }
  for (int t : {0, 1}) {
    st.build(1, n + 1, 1);
    for (int i = 1; i <= n + 1; i++) eves[i].clear();
    for (int i = 1; i <= m; i++) {
      eves[a[i]].push_back(i);
      eves[b[i] + 1].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
      for (int e : eves[i]) st.change(1, n + 1, a[e], n + 1, 1);
      if (i > 1) c[t][i] = st.query(1, n + 1, 1, i, 1);
    }
    for (int i = 1; i <= m; i++) {
      a[i] = n - a[i] + 1;
      b[i] = n - b[i] + 1;
      swap(a[i], b[i]);
    }
  }
  ll ans = ll(n) * (n - 1) * (n - 2) / 6;
  for (int i = 1; i <= n; i++) {
    int j = n - i + 1;
    ll t = c[0][i] + (j - 1 - c[1][j]);
    ans -= t * (t - 1) / 2;
  }
  cout << ans << '\n';
}