#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
} c[110000];
int a[110000], d[110000];
int sum[110000 << 2];
bool is[110000 << 2], cov[110000 << 2];
bool cmp1(const node &a, const node &b) {
  if (a.l != b.l) return a.l < b.l;
  return a.r < b.r;
}
bool cmp2(const node &a, const node &b) {
  if (a.r != b.r) return a.r > b.r;
  return a.l > b.l;
}
void Pushup(int no) { sum[no] = sum[no << 1] + sum[no << 1 | 1]; }
void Pushdown(int no, int len) {
  if (cov[no]) {
    is[no << 1] ^= 1;
    cov[no << 1] ^= 1;
    is[no << 1 | 1] ^= 1;
    cov[no << 1 | 1] ^= 1;
    sum[no << 1] = (len - (len >> 1)) - sum[no << 1];
    sum[no << 1 | 1] = (len >> 1) - sum[no << 1 | 1];
    cov[no] = 0;
  }
}
void update(int l, int r, int no, int st, int en) {
  if (st <= l && r <= en) {
    is[no] ^= 1;
    cov[no] ^= 1;
    sum[no] = r - l + 1 - sum[no];
  } else {
    int mid = l + r >> 1;
    Pushdown(no, r - l + 1);
    if (en <= mid)
      update(l, mid, no << 1, st, en);
    else if (st > mid)
      update(mid + 1, r, no << 1 | 1, st, en);
    else
      update(l, mid, no << 1, st, en), update(mid + 1, r, no << 1 | 1, st, en);
    Pushup(no);
  }
}
int query(int l, int r, int no, int st, int en) {
  if (st <= l && r <= en)
    return sum[no];
  else {
    int mid = l + r >> 1;
    Pushdown(no, r - l + 1);
    if (en <= mid)
      return query(l, mid, no << 1, st, en);
    else if (st > mid)
      return query(mid + 1, r, no << 1 | 1, st, en);
    else
      return query(l, mid, no << 1, st, en) +
             query(mid + 1, r, no << 1 | 1, st, en);
  }
}
int main() {
  int n, m, i, j, k, l, r;
  long long ans;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &c[i].l, &c[i].r);
    c[i].l = lower_bound(a + 1, a + n + 1, c[i].l) - a;
    c[i].r = upper_bound(a + 1, a + n + 1, c[i].r) - a - 1;
  }
  sort(c + 1, c + m + 1, cmp1);
  for (i = 1, j = 1; i <= m; i++) {
    while (j != n && j < c[i].l) {
      d[j] = query(1, n, 1, j + 1, n);
      j++;
    }
    if (c[i].l <= c[i].r) update(1, n, 1, c[i].l, c[i].r);
  }
  while (j != n) {
    d[j] = query(1, n, 1, j + 1, n);
    j++;
  }
  memset(is, 0, sizeof(is));
  memset(sum, 0, sizeof(sum));
  memset(cov, 0, sizeof(cov));
  sort(c + 1, c + m + 1, cmp2);
  for (i = 1, j = n; i <= m; i++) {
    while (j != 1 && j > c[i].r) {
      d[j] += j - 1 - query(1, n, 1, 1, j - 1);
      j--;
    }
    if (c[i].l <= c[i].r) update(1, n, 1, c[i].l, c[i].r);
  }
  while (j != 1) {
    d[j] += j - 1 - query(1, n, 1, 1, j - 1);
    j--;
  }
  for (i = 1, ans = (long long)n * (n - 1) * (n - 2) / 6; i <= n; i++) {
    ans -= (long long)d[i] * (d[i] - 1) / 2;
  }
  printf("%I64d\n", ans);
  return 0;
}
