#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, l, r, val[200005], v[200005], A[200005], b = 0;
  long long int ans = 0;
  cin >> n >> q;
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  while (q--) {
    scanf("%d%d", &l, &r);
    l--;
    r--;
    val[l]++;
    if (r < n - 1) val[r + 1]--;
  }
  for (int i = 0; i < n; i++) {
    b += val[i];
    v[i] = b;
  }
  sort(A, A + n);
  sort(v, v + n);
  for (int i = 0; i < n; i++) ans += (A[i] * 1LL * v[i]);
  cout << ans;
  return 0;
}
