#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, k;
int S[N];
vector<int> Q[N];
struct seg {
  int ones, zeros;
  bool flip;
};
seg st[4 * N];
void pull(int v, int l, int r) {
  if (l == r) return;
  st[v].ones = st[v * 2].ones + st[v * 2 + 1].ones;
  st[v].zeros = st[v * 2].zeros + st[v * 2 + 1].zeros;
}
void build(int v, int l, int r) {
  if (l == r) {
    st[v].ones = 0, st[v].zeros = 1;
    st[v].flip = false;
    return;
  }
  int mid = (l + r) / 2;
  build(v * 2, l, mid);
  build(v * 2 + 1, mid + 1, r);
  pull(v, l, r);
}
void push(int v, int l, int r) {
  if (st[v].flip) {
    swap(st[v].ones, st[v].zeros);
    if (l != r) {
      st[v * 2].flip ^= true;
      st[v * 2 + 1].flip ^= true;
    }
    st[v].flip = false;
  }
}
void update(int v, int l, int r, int ql, int qr) {
  push(v, l, r);
  if (l > qr || ql > r) return;
  if (ql <= l && r <= qr) {
    st[v].flip ^= true;
    push(v, l, r);
    return;
  }
  int mid = (l + r) / 2;
  update(v * 2, l, mid, ql, qr);
  update(v * 2 + 1, mid + 1, r, ql, qr);
  pull(v, l, r);
}
int query(int v, int l, int r, int ql, int qr) {
  push(v, l, r);
  if (l > qr || ql > r) return 0;
  if (ql <= l && r <= qr) {
    return st[v].ones;
  }
  int mid = (l + r) / 2;
  int L = query(v * 2, l, mid, ql, qr);
  int R = query(v * 2 + 1, mid + 1, r, ql, qr);
  return L + R;
}
signed main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", S + i);
  sort(S + 1, S + n + 1);
  for (int i = 1; i <= k; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    int L = lower_bound(S + 1, S + n + 1, u) - (S);
    int R = upper_bound(S + 1, S + n + 1, v) - (S);
    if (L == R - 1) continue;
    Q[L].push_back(R);
    Q[R].push_back(L);
  }
  build(1, 1, n);
  long long ans = (1ll * n * (n - 1) * (n - 2)) / 6ll;
  for (int i = 1; i <= n; i++) {
    for (int R : Q[i]) {
      if (i > R)
        update(1, 1, n, R, i - 1);
      else
        update(1, 1, n, i, R - 1);
    }
    long long cur = query(1, 1, n, 1, i - 1) + query(1, 1, n, i + 1, n);
    update(1, 1, n, i, i);
    cur = (cur * (cur - 1)) / 2ll;
    ans -= cur;
  }
  printf("%I64d\n", ans);
}
