#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
void SOLVE() {
  long long n, q;
  cin >> n >> q;
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<long long> cnt(2e5 + 1, 0);
  while (q--) {
    long long L, R;
    cin >> L >> R;
    L--, R--;
    cnt[L]++;
    cnt[R + 1]--;
  }
  partial_sum(cnt.begin(), cnt.end(), cnt.begin());
  sort(arr.rbegin(), arr.rend());
  vector<pair<long long, long long>> vec;
  for (long long i = 0; i < n; i++) {
    vec.push_back({i, cnt[i]});
  }
  sort(vec.begin(), vec.end(),
       [](const pair<long long, long long> &a,
          const pair<long long, long long> &b) {
         return (a.second > b.second);
       });
  long long ans = 0, idx = 0;
  for (long long i = 0; i < n; i++) {
    if (vec[i].second != 0) {
      ans += (vec[i].second * arr[idx]);
      idx++;
    } else {
      break;
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  long long T = 1;
  for (long long tc = (1); tc < (T + 1); ++tc) {
    SOLVE();
  }
  return 0;
}
