#include <bits/stdc++.h>
using namespace std;
int n, k, s[100010], m, w[100010 * 4], tag[100010 * 4];
struct stu {
  int h, l, r;
} o[100010 * 3];
bool cmp(stu x, stu y) { return x.h < y.h; }
void modify(int k, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    w[k] = r - l + 1 - w[k], tag[k] ^= 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (tag[k]) {
    w[k * 2] = mid - l + 1 - w[k * 2], tag[k * 2] ^= 1;
    w[k * 2 + 1] = r - mid - w[k * 2 + 1], tag[k * 2 + 1] ^= 1;
    tag[k] = 0;
  }
  if (L <= mid) modify(k * 2, l, mid, L, R);
  if (R > mid) modify(k * 2 + 1, mid + 1, r, L, R);
  w[k] = w[k * 2] + w[k * 2 + 1];
}
int query(int k, int l, int r, int X) {
  if (l == r) return w[k];
  int mid = (l + r) >> 1;
  if (tag[k]) {
    w[k * 2] = mid - l + 1 - w[k * 2], tag[k * 2] ^= 1;
    w[k * 2 + 1] = r - mid - w[k * 2 + 1], tag[k * 2 + 1] ^= 1;
    tag[k] = 0;
  }
  if (X <= mid)
    return query(k * 2, l, mid, X);
  else
    return query(k * 2 + 1, mid + 1, r, X);
}
int main() {
  scanf("%d%d", &n, &k);
  s[0] = 0, s[n + 1] = 1e9 + 1;
  for (int i = 1; i <= n; ++i) scanf("%d", &s[i]);
  sort(s + 1, s + n + 1);
  for (int i = 1, a, b; i <= k; ++i) {
    scanf("%d%d", &a, &b);
    a = lower_bound(s, s + n + 2, a) - s;
    b = upper_bound(s, s + n + 2, b) - s - 1;
    if (a == n + 1 || b == 0) continue;
    o[++m].h = a, o[m].l = a, o[m].r = b;
    o[++m].h = b + 1, o[m].l = a, o[m].r = b;
  }
  for (int i = 2; i <= n; ++i) o[++m].h = i, o[m].l = o[m].r = i - 1;
  sort(o + 1, o + m + 1, cmp);
  long long ans = (long long)n * (n - 1) * (n - 2) / 6;
  for (int i = 1; i <= m; ++i) {
    if (i > 1 && o[i].h > o[i - 1].h) {
      long long win = w[1] - query(1, 1, n, o[i - 1].h);
      ans -= win * (win - 1) / 2;
    }
    modify(1, 1, n, o[i].l, o[i].r);
  }
  if (o[m].h == n) {
    long long win = w[1] - query(1, 1, n, n);
    ans -= win * (win - 1) / 2;
  }
  printf("%I64d", ans);
}
