#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const bool db = false;
int n, q, a[200010];
int b[200010], sz;
int t[4 * 200010], x[4 * 200010];
vector<int> ql[200010], qr[200010];
void push(int v, int l, int r) {
  if (x[v] == 1) {
    if (l != r) {
      x[2 * v] ^= x[v];
      x[2 * v + 1] ^= x[v];
    }
    t[v] = r - l + 1 - t[v];
    x[v] = 0;
  }
}
void upd(int v, int L, int R, int l, int r) {
  push(v, L, R);
  if (l > R || r < L) return;
  if (l <= L && R <= r) {
    x[v] ^= 1;
    push(v, L, R);
    return;
  }
  upd(2 * v, L, (L + R) / 2, l, r);
  upd(2 * v + 1, (L + R) / 2 + 1, R, l, r);
  t[v] = t[2 * v] + t[2 * v + 1];
}
int get(int v, int L, int R, int l, int r) {
  push(v, L, R);
  if (l > R || r < L) return 0;
  if (l <= L && R <= r) return t[v];
  int M = (L + R) / 2;
  int ret = 0;
  ret += get(2 * v, L, (L + R) / 2, l, r);
  ret += get(2 * v + 1, (L + R) / 2 + 1, R, l, r);
  t[v] = t[2 * v] + t[2 * v + 1];
  return ret;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    b[sz++] = a[i];
  }
  sort(b, b + sz);
  while (q-- > 0) {
    int l, r;
    scanf("%d%d", &l, &r);
    l = lower_bound(b, b + sz, l) - b + 1;
    r = upper_bound(b, b + sz, r) - b + 1 - 1;
    ql[l].push_back(r);
    qr[r + 1].push_back(l);
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0, s = ql[i].size(); j < s; ++j) {
      upd(1, 1, n, i, ql[i][j]);
    }
    for (int j = 0, s = qr[i].size(); j < s; ++j) {
      upd(1, 1, n, qr[i][j], i - 1);
    }
    long long cur = i - 1 - get(1, 1, n, 1, i - 1) + get(1, 1, n, i + 1, n);
    ans += cur * (cur - 1) / 2;
  }
  cout << 1LL * n * (n - 1) * (n - 2) / 6 - ans << "\n";
  getchar();
  getchar();
  return 0;
}
