#include <bits/stdc++.h>
using namespace std;
int flag[110000 * 4], cnt[110000 * 4][2];
void build(int u, int L, int R) {
  flag[u] = 0;
  cnt[u][0] = R - L;
  cnt[u][1] = 0;
  if (R == L + 1) return;
  build((u << 1), L, ((L + R) >> 1));
  build(((u << 1) + 1), ((L + R) >> 1), R);
}
void push_down(int u) {
  if (flag[u]) {
    flag[(u << 1)] = 1 - flag[(u << 1)];
    flag[((u << 1) + 1)] = 1 - flag[((u << 1) + 1)];
    swap(cnt[(u << 1)][0], cnt[(u << 1)][1]);
    swap(cnt[((u << 1) + 1)][0], cnt[((u << 1) + 1)][1]);
    flag[u] = 0;
  }
}
void push_up(int u) {
  cnt[u][0] = cnt[(u << 1)][0] + cnt[((u << 1) + 1)][0];
  cnt[u][1] = cnt[(u << 1)][1] + cnt[((u << 1) + 1)][1];
}
void flip(int u, int L, int R, int l, int r) {
  l = max(l, L);
  r = min(r, R);
  if (l >= r) return;
  if (l == L && r == R) {
    flag[u] = 1 - flag[u];
    swap(cnt[u][0], cnt[u][1]);
    return;
  }
  push_down(u);
  flip((u << 1), L, ((L + R) >> 1), l, r);
  flip(((u << 1) + 1), ((L + R) >> 1), R, l, r);
  push_up(u);
}
int calc(int u, int L, int R, int l, int r) {
  l = max(l, L);
  r = min(R, r);
  if (l >= r) return 0;
  if (l == L && R == r) return cnt[u][0];
  push_down(u);
  return calc((u << 1), L, ((L + R) >> 1), l, r) +
         calc(((u << 1) + 1), ((L + R) >> 1), R, l, r);
}
int N, M;
int s[110000], w[110000];
pair<int, pair<int, int> > qu[110000 * 2];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) scanf("%d", &s[i]);
  sort(s, s + N);
  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a = lower_bound(s, s + N, a) - s;
    b = upper_bound(s, s + N, b) - s;
    qu[i * 2] = pair<int, pair<int, int> >(a, pair<int, int>(a, b));
    qu[i * 2 + 1] = pair<int, pair<int, int> >(b, pair<int, int>(a, b));
  }
  M *= 2;
  sort(qu, qu + M);
  build(1, 0, N);
  for (int i = 0, j = 0; i < N; i++) {
    while (j < M && qu[j].first <= i) {
      flip(1, 0, N, qu[j].second.first, qu[j].second.second);
      j++;
    }
    w[i] = calc(1, 0, N, 0, i) + (N - i - 1 - calc(1, 0, N, i + 1, N));
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += (long long)w[i] * (N - 1 - w[i]);
  }
  ans -= (long long)N * (N - 1) * (N - 2) / 6;
  ans /= 2;
  printf("%I64d\n", ans);
  return 0;
}
