#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void checkmin(T &a, T b) {
  if (a > b) a = b;
}
const int inf = 1 << 30;
const double eps = 1e-7;
const long long oo = 100000000LL * 100000000LL;
const long long Mod = 1000000007;
inline int LS(const int x) { return x << 1; }
inline int RS(const int x) { return LS(x) ^ 1; }
const int NN = 100000 + 90;
int N, K;
int s[NN], sum[NN << 4], xx[NN << 4];
vector<int> q[NN], rq[NN];
long long ans;
int find_low(int a) {
  int low = 1, high = N, mid;
  while (low < high) {
    mid = (low + high) >> 1;
    if (s[mid] >= a)
      high = mid;
    else
      low = mid + 1;
  }
  return low;
}
int find_high(int a) {
  int low = 1, high = N, mid;
  while (low < high) {
    mid = (low + high + 1) >> 1;
    if (s[mid] <= a)
      low = mid;
    else
      high = mid - 1;
  }
  return low;
}
void down(int l, int r, int idx) {
  if (xx[idx]) {
    int mid = (l + r) >> 1;
    sum[idx << 1] = mid - l + 1 - sum[idx << 1];
    xx[idx << 1] ^= 1;
    sum[idx << 1 | 1] = r - mid - sum[idx << 1 | 1];
    xx[idx << 1 | 1] ^= 1;
    xx[idx] = 0;
  }
}
int query(int idx, int a, int b, int l, int r) {
  if (l == a && r == b) {
    return sum[idx];
  }
  int mid = (l + r) >> 1;
  down(l, r, idx);
  if (b <= mid)
    return query(idx << 1, a, b, l, mid);
  else if (mid < a)
    return query(idx << 1 | 1, a, b, mid + 1, r);
  else
    return query(idx << 1, a, mid, l, mid) +
           query(idx << 1 | 1, mid + 1, b, mid + 1, r);
}
void flip(const int r, const int L, const int R) {
  xx[r] = !xx[r];
  sum[r] = R - L + 1 - sum[r];
}
void flip(int idx, int a, int b, int l, int r) {
  if (a <= l && r <= b) {
    flip(idx, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  if (xx[idx]) {
    xx[idx] = 0;
    flip(idx << 1, l, mid);
    flip(idx << 1 | 1, mid + 1, r);
  }
  if (a <= mid) flip(idx << 1, a, b, l, mid);
  if (b > mid) flip(idx << 1 | 1, a, b, mid + 1, r);
  sum[idx] = sum[idx << 1] + sum[idx << 1 | 1];
}
void solve() {
  int i, j;
  (memset((sum), 0, sizeof(sum)));
  (memset((xx), 0, sizeof(xx)));
  ans = (long long)N * (N - 1) * (N - 2) / 6;
  for (i = (1); i < (N + 1); i++) {
    for (j = (0); j < (q[i].size()); j++) flip(1, i, q[i][j], 1, N);
    long long w = i - 1;
    if (1 <= i - 1) w -= query(1, 1, i - 1, 1, N);
    if (i + 1 <= N) w += query(1, i + 1, N, 1, N);
    ans -= (long long)w * (w - 1) / 2;
    for (j = (0); j < (rq[i].size()); j++) flip(1, rq[i][j], i, 1, N);
  }
  cout << ans << endl;
}
int main() {
  int i, j, a, b;
  while (cin >> N >> K) {
    for (i = (1); i < (N + 1); i++) {
      cin >> s[i];
      q[i].clear();
      rq[i].clear();
    }
    sort(s + 1, s + 1 + N);
    for (i = (0); i < (K); i++) {
      cin >> a >> b;
      if (a > s[N] || b < s[1]) continue;
      a = find_low(a);
      b = find_high(b);
      q[a].push_back(b);
      rq[b].push_back(a);
    }
    solve();
  }
  return 0;
}
