#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
typedef struct node {
  int l, r;
};
struct segtree {
  node seg[maxn << 2];
  int cov[maxn << 2];
  int cnt[maxn << 2][2];
  void pushup(int o) {
    for (int i = 0; i < 2; i++) cnt[o][i] = cnt[o << 1][i] + cnt[o << 1 | 1][i];
  }
  void pushdown(int o) {
    if (cov[o]) {
      cov[o << 1] ^= 1;
      cov[o << 1 | 1] ^= 1;
      swap(cnt[o << 1][0], cnt[o << 1][1]);
      swap(cnt[o << 1 | 1][0], cnt[o << 1 | 1][1]);
      cov[o] = 0;
    }
  }
  void build(int o, int l, int r) {
    seg[o].l = l, seg[o].r = r, cov[o] = 0;
    if (l == r) {
      cnt[o][0] = 1;
      cnt[o][1] = 0;
      return;
    }
    int m = (l + r) >> 1;
    build(o << 1, l, m);
    build(o << 1 | 1, m + 1, r);
    pushup(o);
  }
  void update(int o, int l, int r) {
    if (l <= seg[o].l && seg[o].r <= r) {
      swap(cnt[o][0], cnt[o][1]);
      cov[o] ^= 1;
      return;
    }
    pushdown(o);
    int m = (seg[o].l + seg[o].r) >> 1;
    if (l <= m) update(o << 1, l, r);
    if (r > m) update(o << 1 | 1, l, r);
    pushup(o);
  }
  int query(int o, int l, int r, int v) {
    int ans = 0;
    if (l <= seg[o].l && seg[o].r <= r) return cnt[o][v];
    pushdown(o);
    int m = (seg[o].l + seg[o].r) >> 1;
    if (l <= m) ans += query(o << 1, l, r, v);
    if (r > m) ans += query(o << 1 | 1, l, r, v);
    return ans;
  }
} tree;
int s[maxn];
vector<pair<int, int> > change, other;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  tree.build(1, 1, n);
  sort(s + 1, s + 1 + n);
  for (int i = 0; i < k; i++) {
    int ai, bi;
    scanf("%d%d", &ai, &bi);
    ai = lower_bound(s + 1, s + n + 1, ai) - (s + 1) + 1;
    bi = upper_bound(s + 1, s + 1 + n, bi) - (s + 1);
    if (ai > bi) continue;
    other.push_back(make_pair(bi, ai));
    change.push_back(make_pair(ai, bi));
  }
  sort(change.begin(), change.end());
  sort(other.begin(), other.end());
  long long ans = (long long)n * (n - 1) * (n - 2) / 6;
  for (int i = 1, j = 0, r = 0; i <= n; i++) {
    while (j < change.size() && change[j].first <= i) {
      tree.update(1, change[j].first, change[j].second);
      j++;
    }
    int win = 0;
    if (i > 1) win += tree.query(1, 1, i - 1, 0);
    if (i < n) win += tree.query(1, i + 1, n, 1);
    ans -= (long long)win * (win - 1) / 2;
    while (r < other.size() && other[r].first <= i) {
      tree.update(1, other[r].second, other[r].first);
      r++;
    }
  }
  printf("%I64d\n", ans);
}
