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 MAXN = 1000005;
long long segTree_val[MAXN * 4], segTree_siz[MAXN * 4], segLazy[MAXN * 4];
int n;
void segtree_clear(int x) { segTree_val[x] = segTree_siz[x] = segLazy[x] = 0; }
void segtree_maintain(int x) {
  segTree_val[x] = segTree_val[((x) << 1)] + segTree_val[(((x) << 1) + 1)];
  segTree_siz[x] = segTree_siz[((x) << 1)] + segTree_siz[(((x) << 1) + 1)];
}
void segtree_init(int cl = -1, int cr = -1, int x = -1) {
  if (x == -1) {
    segtree_init(1, n, 1);
    return;
  }
  segtree_clear(x);
  if (cl == cr) {
    segTree_siz[x] = 1;
  } else if (cl < cr) {
    int mid = (cl + cr) >> 1;
    segtree_init(cl, mid, ((x) << 1));
    segtree_init(mid + 1, cr, (((x) << 1) + 1));
    segtree_maintain(x);
  }
}
void segtree_pushdown(int x) {
  if (segLazy[x]) {
    segTree_val[((x) << 1)] = segTree_siz[((x) << 1)] - segTree_val[((x) << 1)];
    segTree_val[(((x) << 1) + 1)] =
        segTree_siz[(((x) << 1) + 1)] - segTree_val[(((x) << 1) + 1)];
    segLazy[((x) << 1)] ^= 1;
    segLazy[(((x) << 1) + 1)] ^= 1;
    segLazy[x] ^= 1;
  }
}
void segtree_revert(int l, int r, int cl = -1, int cr = -1, int x = -1) {
  if (x == -1) {
    segtree_revert(l, r, 1, n, 1);
    return;
  }
  segtree_pushdown(x);
  if (cr < l || cl > r) return;
  if (cl >= l && cr <= r) {
    segTree_val[x] = segTree_siz[x] - segTree_val[x];
    segLazy[x] ^= 1;
    return;
  }
  int mid = (cl + cr) >> 1;
  segtree_revert(l, r, cl, mid, ((x) << 1));
  segtree_revert(l, r, mid + 1, cr, (((x) << 1) + 1));
  segtree_maintain(x);
}
int qres;
void segtree_query(int l, int r, int cl = -1, int cr = -1, int x = -1) {
  if (x == -1) {
    qres = 0;
    segtree_query(l, r, 1, n, 1);
    return;
  }
  segtree_pushdown(x);
  if (cr < l || cl > r) return;
  if (cl >= l && cr <= r) {
    qres += segTree_val[x];
    return;
  }
  int mid = (cl + cr) >> 1;
  segtree_query(l, r, cl, mid, ((x) << 1));
  segtree_query(l, r, mid + 1, cr, (((x) << 1) + 1));
  segtree_maintain(x);
}
int N, K;
long long seq[MAXN];
long long A[MAXN], B[MAXN];
struct Event {
  int r, c, l, typ;
  bool operator<(const Event &b) const {
    if (r != b.r) return r < b.r;
    if (typ != b.typ) return typ > b.typ;
    if (c != b.c) return c < b.c;
    return l < b.l;
  }
} evt[MAXN];
int evttot;
long long wins[MAXN];
void solve() {
  evttot = 0;
  sort(seq, seq + N);
  for (int i = 0; i < K; i++) {
    int l = lower_bound(seq, seq + N, A[i]) - seq;
    if (l == N) continue;
    int r = lower_bound(seq, seq + N, B[i]) - seq;
    if (r == N)
      r--;
    else if (seq[r] > B[i]) {
      r--;
      if (r == -1) continue;
    }
    if (l > r) continue;
    l++, r++;
    evt[evttot++] = {l - 1, l - 1, r - l + 1, 1};
    evt[evttot++] = {r, l - 1, r - l + 1, 2};
  }
  sort(evt, evt + evttot);
  n = N;
  segtree_init();
  for (int u = 0, i = 0; u <= N; u++) {
    if (u) {
      wins[u] = 0;
      segtree_query(u + 1, N);
      wins[u] += qres;
      segtree_query(1, u - 1);
      wins[u] += u - 1 - qres;
    }
    if (evt[i].r == u) {
      int j = i;
      while (evt[j].r == u) {
        segtree_revert(evt[j].c + 1, evt[j].c + evt[j].l);
        j++;
      }
      i = j;
    }
  }
  long long res = (long long)N * (N - 1LL) * (N - 2LL) / 6LL;
  for (int i = 1; i <= N; i++) {
    res -= wins[i] * (wins[i] - 1LL) / 2LL;
  }
  cout << res << endl;
}
int main(int argc, const char *argv[]) {
  while (scanf(" %d %d", &N, &K) != EOF) {
    for (int i = 0; i < N; i++) {
      scanf(" %lld", &seq[i]);
      ;
    }
    for (int i = 0; i < K; i++) {
      scanf(" %lld", &A[i]);
      ;
      scanf(" %lld", &B[i]);
      ;
    }
    solve();
  }
  return 0;
}