#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 17;
long long N, K;
int tree[2 * MAXN];
bool lazy[2 * MAXN];
int nums[MAXN];
void init() {
  for (int i = 0, _i = (MAXN); i < _i; ++i) {
    tree[i] = 0;
    lazy[i] = false;
  }
}
void do_lazy(int node, int s, int e) {
  if (!lazy[node]) return;
  lazy[node] = false;
  tree[node] = e - s - tree[node];
  if (e - s > 1) {
    lazy[2 * node] ^= true;
    lazy[2 * node + 1] ^= true;
  }
}
void flip(int node, int s, int e, int a, int b) {
  do_lazy(node, s, e);
  if (s >= b || a >= e) return;
  if (s >= a && e <= b) {
    lazy[node] ^= true;
    do_lazy(node, s, e);
    return;
  }
  int mid = (s + e) >> 1;
  flip(2 * node, s, mid, a, b);
  flip(2 * node + 1, mid, e, a, b);
  tree[node] = tree[2 * node] + tree[2 * node + 1];
}
int get(int node, int s, int e, int a, int b) {
  do_lazy(node, s, e);
  if (s >= b || a >= e) return 0;
  if (s >= a && e <= b) return tree[node];
  int mid = (s + e) >> 1;
  return get(2 * node, s, mid, a, b) + get(2 * node + 1, mid, e, a, b);
}
vector<tuple<int, int>> events[MAXN];
int main() {
  cin >> N >> K;
  for (int i = 0, _i = (N); i < _i; ++i) {
    cin >> nums[i];
    events[i].emplace_back(i, i + 1);
  }
  sort(nums, nums + N);
  for (int i = 0, _i = (K); i < _i; ++i) {
    int lo, hi;
    cin >> lo >> hi;
    int lo_ind = lower_bound(nums, nums + N, lo) - nums;
    int hi_ind = upper_bound(nums, nums + N, hi) - nums;
    events[lo_ind].emplace_back(lo_ind, hi_ind);
    events[hi_ind].emplace_back(lo_ind, hi_ind);
  }
  long long ans = N * (N - 1) * (N - 2) / 6;
  for (int i = 0, _i = (N); i < _i; ++i) {
    for (auto ev : events[i]) {
      int lo, hi;
      tie(lo, hi) = ev;
      flip(1, 0, MAXN, lo, hi);
    }
    long long deg = get(1, 0, MAXN, 0, MAXN) - get(1, 0, MAXN, i, i + 1);
    ans -= deg * (deg - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
