#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
using namespace std;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const int maxn = 1000 * 100 + 5;
const long long inf = 9223372036854775807;
const long long mod = 1e9 + 7;
long long n, q, seg[2][4 * maxn], lazy[4 * maxn], ans, a[maxn], b[maxn],
    s[maxn];
vector<int> comp, add[maxn], del[maxn];
void build(int x = 1, int lx = 0, int rx = n) {
  if (rx - lx == 1) {
    seg[0][x] = 1;
    return;
  }
  int mid = lx + rx >> 1;
  build(x << 1, lx, mid);
  build(x << 1 | 1, mid, rx);
  seg[0][x] = seg[0][x << 1] + seg[0][x << 1 | 1];
}
inline void shift(int x, int lx, int rx) {
  if (lazy[x]) {
    swap(seg[0][x], seg[1][x]);
    if (rx - lx > 1) {
      lazy[x << 1] ^= 1;
      lazy[x << 1 | 1] ^= 1;
    }
    lazy[x] = 0;
  }
}
void upd(int l, int r, int x = 1, int lx = 0, int rx = n) {
  shift(x, lx, rx);
  if (lx >= r || rx <= l) return;
  if (lx >= l && rx <= r) {
    lazy[x] ^= 1;
    shift(x, lx, rx);
    return;
  }
  int mid = lx + rx >> 1;
  upd(l, r, x << 1, lx, mid);
  upd(l, r, x << 1 | 1, mid, rx);
  seg[1][x] = seg[1][x << 1] + seg[1][x << 1 | 1];
  seg[0][x] = seg[0][x << 1] + seg[0][x << 1 | 1];
}
long long get(int i, int l, int r, int x = 1, int lx = 0, int rx = n) {
  shift(x, lx, rx);
  if (lx >= r || rx <= l) return 0;
  if (lx >= l && rx <= r) {
    return seg[i][x];
  }
  int mid = lx + rx >> 1;
  return get(i, l, r, x << 1, lx, mid) + get(i, l, r, x << 1 | 1, mid, rx);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> q;
  build();
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    comp.push_back(s[i]);
  }
  sort((comp).begin(), (comp).end());
  for (int i = 1; i <= q; i++) {
    cin >> a[i] >> b[i];
    a[i] = lower_bound((comp).begin(), (comp).end(), a[i]) - comp.begin();
    b[i] = upper_bound((comp).begin(), (comp).end(), b[i]) - comp.begin();
    add[a[i]].push_back(b[i]);
    del[b[i]].push_back(a[i]);
  }
  ans = ((n) * (n - 1) * (n - 2)) / 6;
  long long x, y;
  for (int i = 0; i < n; i++) {
    for (auto u : add[i]) {
      upd(i, u);
    }
    for (auto u : del[i]) {
      upd(u, i);
    }
    x = 0, y = 0;
    if (i > 0) {
      x = get(0, 0, i);
    }
    if (i < n - 1) {
      y = get(1, i + 1, n);
    }
    ans -= (x + y) * (x + y - 1) / 2;
  }
  cout << ans;
}
