#include <bits/stdc++.h>
using namespace std;
int N, K;
int S[100010];
pair<int, int> Q[100010];
struct BIT {
  vector<int> tree, lazy;
  void init() {
    tree = vector<int>(4 * N, 0);
    lazy = vector<int>(4 * N, 0);
  }
  void prop(int l, int r, int n) {
    if (l != r && lazy[n]) {
      int m = (l + r) >> 1;
      tree[2 * n] = m - l + 1 - tree[2 * n];
      lazy[2 * n] ^= 1;
      tree[2 * n + 1] = r - m - tree[2 * n + 1];
      lazy[2 * n + 1] ^= 1;
      lazy[n] = 0;
    }
  }
  void upd(int a, int b, int l, int r, int n) {
    if (b < l || r < a) return;
    if (a <= l && r <= b) {
      tree[n] = r - l + 1 - tree[n];
      lazy[n] ^= 1;
      return;
    }
    prop(l, r, n);
    int m = (l + r) >> 1;
    upd(a, b, l, m, 2 * n);
    upd(a, b, m + 1, r, 2 * n + 1);
    tree[n] = tree[2 * n] + tree[2 * n + 1];
  }
  int quer(int a, int b, int l, int r, int n) {
    if (b < l || r < a) return 0;
    if (a <= l && r <= b) return tree[n];
    prop(l, r, n);
    int m = (l + r) >> 1;
    int L = quer(a, b, l, m, 2 * n);
    int R = quer(a, b, m + 1, r, 2 * n + 1);
    return L + R;
  }
} bit;
vector<int> E[100010];
int f(int x) {
  int s = 0, e = N, p = -1;
  while (s <= e) {
    int m = (s + e) >> 1;
    if (x <= S[m]) {
      p = m;
      e = m - 1;
    } else
      s = m + 1;
  }
  return p;
}
int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", &S[i]);
  }
  sort(S, S + N);
  S[N] = 1e9;
  for (int i = 0; i < K; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    Q[i] = {a, b};
  }
  for (int i = 0; i < K; i++) {
    int l = f(Q[i].first);
    int r = f(Q[i].second + 1);
    if (l == -1 || r == -1) continue;
    Q[i] = {l, r - 1};
    E[l].push_back(i);
    E[r].push_back(i);
  }
  bit.init();
  long long ans = 1LL * N * (N - 1) * (N - 2) / 6;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < E[i].size(); j++) {
      int x = E[i][j];
      bit.upd(Q[x].first, Q[x].second, 0, N - 1, 1);
    }
    int t = i - bit.quer(0, i - 1, 0, N - 1, 1);
    int d = bit.quer(i + 1, N - 1, 0, N - 1, 1);
    ans -= 1LL * (t + d) * (t + d - 1) / 2;
  }
  printf("%lld", ans);
}
