#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int SS = 4 * N;
int sum[SS];
bool lazy[SS];
int n, m;
int a[N], d[N];
pair<int, int> p[N];
void update(int v, int s, int e, bool t) {
  if (t) sum[v] = e - s - sum[v];
  lazy[v] ^= t;
}
void shift(int v, int s, int e) {
  int mid = (s + e) / 2;
  update(2 * v, s, mid, lazy[v]);
  update(2 * v + 1, mid, e, lazy[v]);
  lazy[v] = 0;
}
void flip(int l, int r, int s = 0, int e = n, int v = 1) {
  if (l >= e || r <= s) return;
  if (l <= s && e <= r) {
    update(v, s, e, 1);
    return;
  }
  shift(v, s, e);
  int mid = (s + e) / 2;
  flip(l, r, s, mid, 2 * v);
  flip(l, r, mid, e, 2 * v + 1);
  sum[v] = sum[2 * v] + sum[2 * v + 1];
}
int get(int l, int r, int s = 0, int e = n, int v = 1) {
  if (l >= e || r <= s) return 0;
  if (l <= s && e <= r) return sum[v];
  shift(v, s, e);
  int mid = (s + e) / 2;
  int res = 0;
  res += get(l, r, s, mid, 2 * v);
  res += get(l, r, mid, e, 2 * v + 1);
  return res;
}
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
    p[i].first = lower_bound(a, a + n, p[i].first) - a;
    p[i].second = upper_bound(a, a + n, p[i].second) - a;
  }
  sort(p, p + m);
  int pos = 0;
  for (int i = 0; i < n; i++) {
    while (pos < m && p[pos].first <= i)
      flip(p[pos].first, p[pos].second), pos++;
    d[i] += get(i + 1, n);
  }
  memset(sum, 0, sizeof sum);
  memset(lazy, 0, sizeof lazy);
  sort(p, p + m, cmp);
  pos = 0;
  for (int i = n - 1; i >= 0; i--) {
    while (pos < m && p[pos].second > i)
      flip(p[pos].first, p[pos].second), pos++;
    d[i] += i - get(0, i);
  }
  long long ans = 1LL * (n) * (n - 1) * (n - 2) / 6;
  for (int i = 0; i < n; i++) ans -= 1LL * (d[i]) * (d[i] - 1) / 2;
  cout << ans << "\n";
}
