#include <bits/stdc++.h>
long long n, q, inp[222222], ind[222222], l, r, ans;
int comp(const void *a, const void *b) {
  long long aa = *(long long *)a, bb = *(long long *)b;
  return aa < bb ? -1 : aa > bb ? 1 : 0;
}
int main() {
  scanf("%lld%lld", &n, &q);
  for (long long i = 1; i <= n; i++) scanf("%lld", &inp[i]);
  for (long long i = 1; i <= q; i++) {
    scanf("%lld%lld", &l, &r);
    ind[l]++;
    if (r <= n) ind[r + 1]--;
  }
  for (long long i = 2; i <= n; i++) ind[i] += ind[i - 1];
  qsort(inp, n + 1, sizeof(*inp), comp);
  qsort(ind, n + 1, sizeof(*ind), comp);
  for (long long i = 1; i <= n; i++) ans += inp[i] * ind[i];
  printf("%lld", ans);
}
