#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;
int n, k, t;
int s[MAXN];
int xo[MAXN], tot[MAXN];
pair<int, int> q[MAXN];
void push(int v, int len) {
  xo[v] = 0;
  tot[v] = len - tot[v];
  xo[(v << 1) + 1] ^= 1;
  xo[(v << 1) + 2] ^= 1;
}
void mod(int l, int r, int L, int R, int v) {
  if (xo[v]) push(v, R - L + 1);
  if (l > R || r < L) return;
  if (l <= L && R <= r)
    xo[v] ^= 1, push(v, R - L + 1);
  else
    mod(l, r, L, (L + R) >> 1, (v << 1) + 1),
        mod(l, r, ((L + R) >> 1) + 1, R, (v << 1) + 2),
        tot[v] = tot[(v << 1) + 1] + tot[(v << 1) + 2];
}
int sum(int l, int r, int L, int R, int v) {
  if (xo[v]) push(v, R - L + 1);
  if (l > R || r < L) return 0;
  if (l <= L && R <= r) return tot[v];
  int ret = sum(l, r, L, (L + R) >> 1, (v << 1) + 1) +
            sum(l, r, ((L + R) >> 1) + 1, R, (v << 1) + 2);
  tot[v] = tot[(v << 1) + 1] + tot[(v << 1) + 2];
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", s + i);
  sort(s, s + n);
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = lower_bound(s, s + n, x) - s;
    y = lower_bound(s, s + n, y + 1) - 1 - s;
    if (x <= y) q[t++] = make_pair(x, y), q[t++] = make_pair(y + 1, x);
  }
  sort(q, q + t);
  long long res = 1LL * n * (n - 1) * (n - 2) / 6;
  for (int i = 0, j = 0; i < n; i++) {
    for (; j < t && q[j].first <= i; j++)
      if (q[j].first > q[j].second)
        mod(q[j].second, q[j].first - 1, 0, n - 1, 0);
      else
        mod(q[j].first, q[j].second, 0, n - 1, 0);
    int r1 = sum(i + 1, n - 1, 0, n - 1, 0),
        l1 = i - sum(0, i - 1, 0, n - 1, 0);
    int t1 = r1 + l1;
    res -= 1LL * t1 * (t1 - 1) / 2;
  }
  printf("%I64d\n", res);
  return 0;
}
