#include <bits/stdc++.h>
using namespace std;
long long a[200002];
long long m[200002];
int n, q, t1, t2;
long long res = 0;
int main() {
  cin >> n >> q;
  for (int i = 0; i < n; ++i) cin >> m[i];
  for (int i = 0; i < q; ++i) {
    cin >> t1 >> t2;
    a[t1 - 1]++;
    a[t2]--;
  }
  for (int i = 1; i < n; ++i) a[i] += a[i - 1];
  sort(a, a + n);
  sort(m, m + n);
  for (int i = 0; i < n; ++i) res += a[i] * m[i];
  cout << res << endl;
  return 0;
}
