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;
int n, m, d[100010], w[100010];
struct epoch {
  int x, y;
} a[100010];
struct tnode {
  int tag, b, w;
} tr[100010 * 4];
int find_bg(int ave) {
  int l = 1, r = n, ans = n + 1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (d[mid] >= ave)
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  return ans;
}
int find_sm(int ave) {
  int l = 1, r = n, ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (d[mid] <= ave)
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return ans;
}
bool cmp(epoch a, epoch b) { return a.x < b.x; }
bool _cmp(epoch a, epoch b) { return a.y > b.y; }
void pushdown(int p) {
  int l = p * 2, r = p * 2 + 1;
  if (tr[p].tag) {
    swap(tr[l].b, tr[l].w), tr[l].tag ^= 1;
    swap(tr[r].b, tr[r].w), tr[r].tag ^= 1;
    tr[p].tag = 0;
  }
}
void update(int p) {
  int l = p * 2, r = p * 2 + 1;
  tr[p].b = tr[l].b + tr[r].b;
  tr[p].w = tr[l].w + tr[r].w;
}
void build(int p, int l, int r) {
  tr[p].tag = tr[p].b = 0, tr[p].w = r - l + 1;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(p * 2, l, mid), build(p * 2 + 1, mid + 1, r);
}
void modify(int p, int l, int r, int lx, int rx) {
  if (l == lx && r == rx) {
    swap(tr[p].b, tr[p].w);
    tr[p].tag ^= 1;
    return;
  }
  int mid = (l + r) / 2;
  pushdown(p);
  if (rx <= mid)
    modify(p * 2, l, mid, lx, rx);
  else if (lx > mid)
    modify(p * 2 + 1, mid + 1, r, lx, rx);
  else
    modify(p * 2, l, mid, lx, mid), modify(p * 2 + 1, mid + 1, r, mid + 1, rx);
  update(p);
}
int query(int p, int l, int r, int lx, int rx) {
  if (l == lx && r == rx) return tr[p].w;
  int mid = (l + r) / 2;
  pushdown(p);
  if (rx <= mid) return query(p * 2, l, mid, lx, rx);
  if (lx > mid) return query(p * 2 + 1, mid + 1, r, lx, rx);
  return query(p * 2, l, mid, lx, mid) +
         query(p * 2 + 1, mid + 1, r, mid + 1, rx);
}
int _query(int p, int l, int r, int lx, int rx) {
  if (l == lx && r == rx) return tr[p].b;
  int mid = (l + r) / 2;
  pushdown(p);
  if (rx <= mid) return _query(p * 2, l, mid, lx, rx);
  if (lx > mid) return _query(p * 2 + 1, mid + 1, r, lx, rx);
  return _query(p * 2, l, mid, lx, mid) +
         _query(p * 2 + 1, mid + 1, r, mid + 1, rx);
}
int main() {
  scanf("%d%d", &n, &m);
  long long ans = (long long)(n - 2) * (long long)(n - 1) * n / 6;
  for (int i = 1; i <= n; ++i) scanf("%d", &d[i]);
  sort(d + 1, d + n + 1);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d", &a[i].x, &a[i].y), a[i].x = find_bg(a[i].x),
                                     a[i].y = find_sm(a[i].y);
  for (int i = 1; i <= n; ++i) w[i] = 0;
  sort(a + 1, a + m + 1, cmp);
  int top = 1;
  build(1, 1, n);
  for (int i = 1; i < n; ++i) {
    while (top <= m && a[top].x <= i) {
      if (i <= a[top].y) modify(1, 1, n, i, a[top].y);
      ++top;
    }
    w[i] += query(1, 1, n, i + 1, n);
  }
  sort(a + 1, a + m + 1, _cmp);
  top = 1, build(1, 1, n);
  for (int i = n; i > 1; --i) {
    while (top <= m && a[top].y >= i) {
      if (a[top].x <= i) modify(1, 1, n, a[top].x, i);
      ++top;
    }
    w[i] += _query(1, 1, n, 1, i - 1);
  }
  for (int i = 1; i <= n; ++i) ans -= (long long)w[i] * (w[i] - 1) / 2;
  printf("%I64d", ans);
  return 0;
}