#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  vector<long long> orders(n + 1, 0);
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    orders[l]++;
    orders[r + 1]--;
  }
  for (int i = 1; i < n; i++) orders[i] += orders[i - 1];
  orders.resize(n);
  sort(orders.begin(), orders.end());
  sort(v.begin(), v.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += v[i] * orders[i];
  cout << ans << endl;
  return 0;
}
