#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const long double EPS = 1e-12;
const int INF = 1e9 + 10;
const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100;
const int MN = 1e5 + 10;
vector<int> fir[MN], lst[MN];
int arr[MN];
int n, q, sz;
pair<int, int> inv[MN];
bool lz[4 * MN];
int seg[4 * MN];
void input() {
  cin >> n >> q;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  sort(arr, arr + n);
  while (q--) {
    int l, r;
    cin >> l >> r;
    int L = lower_bound(arr, arr + n, l) - arr;
    int R = upper_bound(arr, arr + n, r) - arr;
    if (L >= R) continue;
    --R;
    if (L == R) continue;
    inv[sz++] = make_pair(L, R);
    lst[R].push_back(sz - 1), fir[L].push_back(sz - 1);
  }
}
void shift(int segnum, int left, int right) {
  if (lz[segnum] == false) return;
  int mid = (left + right) >> 1;
  lz[2 * segnum] = !lz[2 * segnum], lz[2 * segnum + 1] = !lz[2 * segnum + 1];
  lz[segnum] = false;
  seg[2 * segnum] = (mid - left + 1) - seg[2 * segnum];
  seg[2 * segnum + 1] = (right - mid) - seg[2 * segnum + 1];
}
void upd(int segnum, int left, int right, int l, int r) {
  if (r < left || right < l) return;
  if (l <= left && right <= r) {
    lz[segnum] = !lz[segnum];
    seg[segnum] = (right - left + 1) - seg[segnum];
    return;
  }
  shift(segnum, left, right);
  int mid = (left + right) >> 1;
  upd(2 * segnum, left, mid, l, r);
  upd(2 * segnum + 1, mid + 1, right, l, r);
  seg[segnum] = seg[2 * segnum] + seg[2 * segnum + 1];
}
int get(int segnum, int left, int right, int l, int r) {
  if (r < left || right < l) return 0;
  if (l <= left && right <= r) return seg[segnum];
  shift(segnum, left, right);
  int mid = (left + right) >> 1;
  return get(2 * segnum, left, mid, l, r) +
         get(2 * segnum + 1, mid + 1, right, l, r);
}
void solve() {
  long long ans = 1ll * n * (n - 1) * (n - 2) / 6;
  for (int i = 0; i < n; ++i) {
    upd(1, 0, n - 1, i, n - 1);
    for (int j = 0; j < ((int)(fir[i]).size()); ++j)
      upd(1, 0, n - 1, inv[fir[i][j]].first, inv[fir[i][j]].second);
    if (i - 1 >= 0) {
      for (int j = 0; j < ((int)(lst[i - 1]).size()); ++j)
        upd(1, 0, n - 1, inv[lst[i - 1][j]].first, inv[lst[i - 1][j]].second);
    }
    int t = 0;
    if (i - 1 >= 0) t += get(1, 0, n - 1, 0, i - 1);
    if (i != n - 1) t += get(1, 0, n - 1, i + 1, n);
    upd(1, 0, n - 1, i, n - 1);
    long long val = 1ll * t * (t - 1) / 2;
    ans -= val;
  }
  cout << ans << '\n';
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  input();
  solve();
  return 0;
}
