#include <bits/stdc++.h>
using namespace std;
int n, m, d[100010], w[100010];
struct epoch {
  int x, y;
} a[100010];
struct tnode {
  int tag, b, w;
} tr[100010 * 4];
int find_bg(int ave) {
  int l = 1, r = n, ans = n + 1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (d[mid] >= ave)
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  return ans;
}
int find_sm(int ave) {
  int l = 1, r = n, ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (d[mid] <= ave)
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return ans;
}
bool cmp(epoch a, epoch b) { return a.x < b.x; }
bool _cmp(epoch a, epoch b) { return a.y > b.y; }
void pushdown(int p) {
  int l = p * 2, r = p * 2 + 1;
  if (tr[p].tag) {
    swap(tr[l].b, tr[l].w), tr[l].tag ^= 1;
    swap(tr[r].b, tr[r].w), tr[r].tag ^= 1;
    tr[p].tag = 0;
  }
}
void update(int p) {
  int l = p * 2, r = p * 2 + 1;
  tr[p].b = tr[l].b + tr[r].b;
  tr[p].w = tr[l].w + tr[r].w;
}
void build(int p, int l, int r) {
  tr[p].tag = tr[p].b = 0, tr[p].w = r - l + 1;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(p * 2, l, mid), build(p * 2 + 1, mid + 1, r);
}
void modify(int p, int l, int r, int lx, int rx) {
  if (l == lx && r == rx) {
    swap(tr[p].b, tr[p].w);
    tr[p].tag ^= 1;
    return;
  }
  int mid = (l + r) / 2;
  pushdown(p);
  if (rx <= mid)
    modify(p * 2, l, mid, lx, rx);
  else if (lx > mid)
    modify(p * 2 + 1, mid + 1, r, lx, rx);
  else
    modify(p * 2, l, mid, lx, mid), modify(p * 2 + 1, mid + 1, r, mid + 1, rx);
  update(p);
}
int query(int p, int l, int r, int lx, int rx) {
  if (l == lx && r == rx) return tr[p].w;
  int mid = (l + r) / 2;
  pushdown(p);
  if (rx <= mid) return query(p * 2, l, mid, lx, rx);
  if (lx > mid) return query(p * 2 + 1, mid + 1, r, lx, rx);
  return query(p * 2, l, mid, lx, mid) +
         query(p * 2 + 1, mid + 1, r, mid + 1, rx);
}
int _query(int p, int l, int r, int lx, int rx) {
  if (l == lx && r == rx) return tr[p].b;
  int mid = (l + r) / 2;
  pushdown(p);
  if (rx <= mid) return _query(p * 2, l, mid, lx, rx);
  if (lx > mid) return _query(p * 2 + 1, mid + 1, r, lx, rx);
  return _query(p * 2, l, mid, lx, mid) +
         _query(p * 2 + 1, mid + 1, r, mid + 1, rx);
}
int main() {
  scanf("%d%d", &n, &m);
  long long ans = (long long)(n - 2) * (long long)(n - 1) * n / 6;
  for (int i = 1; i <= n; ++i) scanf("%d", &d[i]);
  sort(d + 1, d + n + 1);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d", &a[i].x, &a[i].y), a[i].x = find_bg(a[i].x),
                                     a[i].y = find_sm(a[i].y);
  for (int i = 1; i <= n; ++i) w[i] = 0;
  sort(a + 1, a + m + 1, cmp);
  int top = 1;
  build(1, 1, n);
  for (int i = 1; i < n; ++i) {
    while (top <= m && a[top].x <= i) {
      if (i <= a[top].y) modify(1, 1, n, i, a[top].y);
      ++top;
    }
    w[i] += query(1, 1, n, i + 1, n);
  }
  sort(a + 1, a + m + 1, _cmp);
  top = 1, build(1, 1, n);
  for (int i = n; i > 1; --i) {
    while (top <= m && a[top].y >= i) {
      if (a[top].x <= i) modify(1, 1, n, a[top].x, i);
      ++top;
    }
    w[i] += _query(1, 1, n, 1, i - 1);
  }
  for (int i = 1; i <= n; ++i) ans -= (long long)w[i] * (w[i] - 1) / 2;
  printf("%I64d", ans);
  return 0;
}
