#include <bits/stdc++.h>
const long long oo = 1e16;
using namespace std;
const int N = 200005;
long long pref[N];
int start[N], ending[N];
int a[N], l[N], r[N], rep[N], res[N];
vector<pair<int, int> > v;
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1, greater<int>());
  for (int i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
    start[l[i]]++;
    ending[r[i]]++;
  }
  int prev = 0;
  for (int i = 1; i <= n; i++) {
    prev += start[i];
    rep[i] = prev;
    prev -= ending[i];
    v.push_back({rep[i], i});
  }
  sort(v.begin(), v.end(), greater<pair<int, int> >());
  int j = 1;
  for (auto x : v) {
    int id = x.second;
    res[id] = a[j++];
  }
  pref[1] = 1LL * res[1];
  for (int i = 2; i <= n; i++) pref[i] = pref[i - 1] + res[i];
  long long sum = 0;
  for (int i = 0; i < q; i++) {
    sum += pref[r[i]] - pref[l[i] - 1];
  }
  cout << sum;
  return 0;
}
