#include <bits/stdc++.h>
int n, Q, ql, qr;
long long ans, cnt, tmp;
int sum[400010], set[400010], a[100010];
struct QUERY {
  int l, r;
} beg[100010], end[100010];
int cmp(const void *i, const void *j) { return *(int *)i - *(int *)j; }
int cmp1(const void *i, const void *j) {
  struct QUERY *c = (struct QUERY *)i;
  struct QUERY *d = (struct QUERY *)j;
  return c->l - d->l;
}
int cmp2(const void *i, const void *j) {
  struct QUERY *c = (struct QUERY *)i;
  struct QUERY *d = (struct QUERY *)j;
  return c->r - d->r;
}
void cal(int u, int l, int r) { sum[u] = r - l + 1 - sum[u]; }
void pushup(int u) { sum[u] = sum[u << 1] + sum[u << 1 | 1]; }
void pushdown(int u, int l, int r) {
  int lc = u << 1, rc = u << 1 | 1, mid = (l + r) >> 1;
  set[lc] ^= 1;
  cal(lc, l, mid);
  set[rc] ^= 1;
  cal(rc, mid + 1, r);
  set[u] = 0;
}
void update(int u, int l, int r) {
  int mid = (l + r) >> 1;
  if (ql <= l && r <= qr) {
    set[u] ^= 1;
    cal(u, l, r);
    return;
  }
  if (set[u]) pushdown(u, l, r);
  if (ql <= mid) update(u << 1, l, mid);
  if (qr > mid) update(u << 1 | 1, mid + 1, r);
  pushup(u);
}
void query(int u, int l, int r) {
  int mid = (l + r) >> 1;
  if (ql <= l && r <= qr) {
    cnt += sum[u];
    return;
  }
  if (set[u]) pushdown(u, l, r);
  if (ql <= mid) query(u << 1, l, mid);
  if (qr > mid) query(u << 1 | 1, mid + 1, r);
}
int bi_search1(int num) {
  int l = 0, r = n, mid, ret;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (a[mid] >= num)
      ret = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  return ret;
}
int bi_search2(int num) {
  int l = 0, r = n, mid, ret;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (a[mid] <= num)
      ret = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return ret;
}
int main() {
  int i, j, k;
  scanf("%d%d", &n, &Q);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  qsort(a + 1, n, sizeof(int), cmp);
  for (i = 1; i <= Q; i++) {
    scanf("%d%d", &beg[i].l, &beg[i].r);
    beg[i].l = bi_search1(beg[i].l);
    beg[i].r = bi_search2(beg[i].r);
    if (beg[i].r < beg[i].l) beg[i].l = beg[i].r = -1;
    end[i] = beg[i];
  }
  qsort(beg + 1, Q, sizeof(struct QUERY), cmp1);
  qsort(end + 1, Q, sizeof(struct QUERY), cmp2);
  ans = n * (long long)(n - 1) * (long long)(n - 2) / 6;
  j = 1;
  while (beg[j].l == -1) j++;
  k = 1;
  while (beg[k].r == -1) k++;
  for (i = 1; i <= n; i++) {
    while (j <= Q && beg[j].l != -1 && beg[j].l <= i) {
      ql = beg[j].l;
      qr = beg[j].r;
      update(1, 1, n);
      j++;
    }
    while (k <= Q && beg[j].r != -1 && end[k].r < i) {
      ql = end[k].l;
      qr = end[k].r;
      update(1, 1, n);
      k++;
    }
    tmp = 0;
    if (i != 1) {
      cnt = 0;
      ql = 1;
      qr = i - 1;
      query(1, 1, n);
      tmp = i - 1 - cnt;
    }
    if (i != n) {
      cnt = 0;
      ql = i + 1;
      qr = n;
      query(1, 1, n);
      tmp += cnt;
    }
    ans -= tmp * (tmp - 1) / 2;
  }
  printf("%I64d\n", ans);
  return 0;
}
