#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, l, r;
  cin >> n >> q;
  long long a[n];
  int ac[200001];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    ac[l - 1]--;
    ac[r]++;
  }
  int st = 0;
  long long cnt[200001];
  for (int i = 200000; i >= 0; i--) {
    st += ac[i];
    cnt[i] = st;
  }
  sort(cnt + 1, cnt + 200001, greater<int>());
  sort(a, a + n, greater<int>());
  long long result = 0;
  for (int i = 0; i < n; i++) result += a[i] * cnt[i + 1];
  cout << result << '\n';
  return 0;
}
