#include <bits/stdc++.h>
using namespace std;
void read(int& a) {
  a = 0;
  char k = getchar();
  int f = 1;
  for (; !isdigit(k); k = getchar())
    if (k == '-') f = -1;
  for (; isdigit(k); k = getchar()) a = a * 10 + k - '0';
  a *= f;
}
const int N = 3e5 + 5;
int n, m, tot, a[N], l[N], r[N], c[N];
vector<int> I[N], J[N];
int ch[N << 1][2], sum[N << 1], gfuhsd, tag[N << 1];
int build(int u, int v) {
  int now = ++gfuhsd;
  if (u == v) return now;
  int mid = (u + v) >> 1;
  ch[now][0] = build(u, mid);
  ch[now][1] = build(mid + 1, v);
  return now;
}
void pushdown(int p, int l, int r) {
  if (tag[p]) {
    int mid = (l + r) >> 1;
    tag[ch[p][0]] ^= 1, tag[ch[p][1]] ^= 1;
    sum[ch[p][0]] = mid - l + 1 - sum[ch[p][0]];
    sum[ch[p][1]] = r - mid - sum[ch[p][1]];
    tag[p] = 0;
  }
}
void rev(int p, int l, int r, int u, int v) {
  if (u > v) return;
  if (u <= l && v >= r) {
    sum[p] = r - l + 1 - sum[p];
    tag[p] ^= 1;
    return;
  }
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (u <= mid) rev(ch[p][0], l, mid, u, v);
  if (v > mid) rev(ch[p][1], mid + 1, r, u, v);
  sum[p] = sum[ch[p][0]] + sum[ch[p][1]];
  return;
}
int query(int p, int l, int r, int u, int v, int k) {
  if (u > v) return 0;
  if (u <= l && v >= r) return k ? sum[p] : (r - l + 1 - sum[p]);
  pushdown(p, l, r);
  int mid = (l + r) >> 1, res = 0;
  if (u <= mid) res += query(ch[p][0], l, mid, u, v, k);
  if (v > mid) res += query(ch[p][1], mid + 1, r, u, v, k);
  return res;
}
long long calc(int p) { return 1LL * p * (p - 1) / 2; }
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; ++i) read(a[i]), c[++tot] = a[i];
  sort(c + 1, c + tot + 1);
  tot = unique(c + 1, c + tot + 1) - c - 1;
  for (int i = 1; i <= n; ++i) a[i] = lower_bound(c + 1, c + tot + 1, a[i]) - c;
  for (int i = 1; i <= m; ++i) {
    read(l[i]), read(r[i]);
    l[i] = lower_bound(c + 1, c + tot + 1, l[i]) - c;
    r[i] = upper_bound(c + 1, c + tot + 1, r[i]) - c - 1;
  }
  for (int i = 1; i <= m; ++i) I[l[i]].push_back(i), J[r[i]].push_back(i);
  build(1, tot);
  long long ans = 0;
  for (int i = 1; i <= tot; ++i) {
    for (int j = 0; j < (signed)I[i].size(); ++j) {
      int id = I[i][j];
      rev(1, 1, tot, l[id], r[id]);
    }
    ans +=
        calc(query(1, 1, tot, 1, i - 1, 0) + query(1, 1, tot, i + 1, tot, 1));
    for (int j = 0; j < (signed)J[i].size(); ++j) {
      int id = J[i][j];
      rev(1, 1, tot, l[id], r[id]);
    }
  }
  printf("%I64d\n", 1LL * n * (n - 1) * (n - 2) / 6 - ans);
  return 0;
}
