#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <ctime>
#include <cstdlib>
using namespace std;
#define inf 0x3f3f3f3f
#define N 100020
#define LL long long
#define mod 1000000009
#define ls (i << 1)
#define rs (ls | 1)
#define md (ll + rr >> 1)
#define lson ll, md, ls
#define rson md + 1, rr, rs
int n, k;
int a[N];
struct node {
int x, l, r;
node() {}
node(int x, int l, int r):x(x), l(l), r(r) {}
bool operator < (const node &b) const {
return x < b.x;
}
}b[N*2];
int cnt;
int s[N<<2], fp[N<<2];
void upd(int ll, int rr, int i) {
fp[i] ^= 1;
s[i] = rr - ll + 1 - s[i];
}
void pushDown(int ll, int rr, int i) {
if(fp[i]) {
upd(lson);
upd(rson);
fp[i] = 0;
}
}
void update(int l, int r, int ll, int rr, int i) {
if(l > r) return;
if(ll == l && rr == r) {
fp[i] ^= 1;
s[i] = rr - ll + 1 - s[i];
return;
}
pushDown(ll, rr, i);
if(r <= md) update(l, r, lson);
else if(l > md) update(l, r, rson);
else {
update(l, md, lson);
update(md + 1, r, rson);
}
s[i] = s[ls] + s[rs];
}
int query(int l, int r, int ll, int rr, int i) {
if(l > r) return 0;
if(ll == l && rr == r) return s[i];
pushDown(ll, rr, i);
if(r <= md) return query(l, r, lson);
if(l > md) return query(l, r, rson);
return query(l, md, lson) + query(md + 1, r, rson);
}
int main() {
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= k; ++i) {
int x, y;
scanf("%d%d", &x, &y);
x = lower_bound(a + 1, a + n + 1, x) - a;
if(x > n) continue;
y = upper_bound(a + 1, a + n + 1, y) - a - 1;
if(y < 1) continue;
b[++cnt] = node(x, x, y);
if(y < n) b[++cnt] = node(y + 1, x, y);
}
sort(b + 1, b + cnt + 1);
int j = 1;
LL ans = 1LL * n * (n - 1) * (n - 2) / 6;
for(int i = 1; i <= n; ++i) {
while(j <= cnt && b[j].x <= i) {
update(b[j].l, b[j].r, 1, n, 1);
++j;
}
int x = 0, y = 0;
if(i < n) x = query(i + 1, n, 1, n, 1);
if(i > 1) y = query(1, i - 1, 1, n, 1);
int w = x + i - 1 - y;
ans -= 1LL * w * (w - 1) / 2;
}
cout << ans << endl;
return 0;
}