#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int mod = 1000000007;
long long Mod(long long x) { return x >= mod ? x - mod : x; }
long long read() {
  long long x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
const int N = 100010;
struct tree {
  int l, r, len;
  int lz, val;
} t[N << 2];
void build(int now, int l, int r) {
  t[now].l = l, t[now].r = r, t[now].len = r - l + 1;
  if (l == r) return;
  int mid = l + r >> 1;
  build(now << 1, l, mid), build(now << 1 | 1, mid + 1, r);
}
void pushup(int now) { t[now].val = t[now << 1].val + t[now << 1 | 1].val; }
void pushr(int now) {
  t[now].val = t[now].len - t[now].val;
  t[now].lz ^= 1;
}
void pushdown(int now) {
  if (t[now].lz) pushr(now << 1), pushr(now << 1 | 1), t[now].lz = 0;
}
void reverse(int now, int l, int r) {
  if (t[now].l == l && t[now].r == r) {
    pushr(now);
    return;
  }
  pushdown(now);
  int mid = t[now].l + t[now].r >> 1;
  if (r <= mid)
    reverse(now << 1, l, r);
  else if (l > mid)
    reverse(now << 1 | 1, l, r);
  else
    reverse(now << 1, l, mid), reverse(now << 1 | 1, mid + 1, r);
  pushup(now);
}
int query(int now, int l, int r) {
  if (t[now].l == l && t[now].r == r) return t[now].val;
  pushdown(now);
  int mid = t[now].l + t[now].r >> 1;
  if (r <= mid) return query(now << 1, l, r);
  if (l > mid) return query(now << 1 | 1, l, r);
  return query(now << 1, l, mid) + query(now << 1 | 1, mid + 1, r);
}
int n, m, s[N];
long long ans;
struct area {
  int l, r;
} a[N], b[N];
int main() {
  n = read(), m = read();
  ans = (long long)n * (n - 1) * (n - 2) / 6;
  build(1, 1, n);
  for (int i = 1; i <= n; i++) s[i] = read();
  sort(s + 1, s + 1 + n);
  for (int i = 1; i <= m; i++) {
    a[i].l = b[i].l = lower_bound(s + 1, s + 1 + n, read()) - s;
    a[i].r = b[i].r = upper_bound(s + 1, s + 1 + n, read()) - s - 1;
    if (a[i].l > a[i].r) i--, m--;
  }
  sort(a + 1, a + 1 + m, [&](area u, area v) { return u.l < v.l; });
  sort(b + 1, b + 1 + m, [&](area u, area v) { return u.r < v.r; });
  int p(0), q(0);
  for (int i = 1; i <= n; i++) {
    while (p < m && a[p + 1].l <= i) p++, reverse(1, a[p].l, a[p].r);
    while (q < m && b[q + 1].r < i) q++, reverse(1, b[q].l, b[q].r);
    long long d = 0;
    if (i > 1) d += (i - 1) - query(1, 1, i - 1);
    if (i < n) d += query(1, i + 1, n);
    ans -= d * (d - 1) / 2;
  }
  print(ans), putchar('\n');
  return 0;
}
