#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> p[200005], q[200005];
long long int a[200005], res[200005], pr[200005], qu, sm = 0, n, r[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> qu;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < qu; i++) {
    cin >> q[i].first >> q[i].second;
    q[i].first--, q[i].second--;
    r[q[i].first]++, r[q[i].second + 1]--;
  }
  for (int i = 0; i < n; i++) {
    sm += r[i];
    p[i] = make_pair(sm, i);
  }
  sort(p, p + n);
  sort(a, a + n);
  for (int i = 0; i < n; i++) res[p[i].second] = a[i];
  for (int i = 0; i < n; i++) {
    pr[i] = res[i];
    if (i > 0) pr[i] += pr[i - 1];
  }
  sm = 0;
  for (int i = 0; i < qu; i++)
    sm += (res[q[i].first] + pr[q[i].second] - pr[q[i].first]);
  cout << sm << "\n";
  return 0;
}
