#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, i;
  cin >> n >> q;
  long long arr[200001];
  arr[0] = 0;
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &arr[i]);
  }
  int range[200002] = {0}, l, r;
  while (q--) {
    scanf("%I64d%I64d", &l, &r);
    range[l] += 1;
    range[r + 1] += -1;
  }
  for (i = 1; i <= n; i++) range[i] += range[i - 1];
  int start, end, cnt = 0;
  for (i = 1; i <= n; i++) {
    if (range[i] != 0) break;
  }
  cnt = range[i];
  start = i;
  vector<pair<int, pair<int, int> > > v;
  for (int j = i + 1; j <= n; j++) {
    if (range[j] != cnt) {
      v.push_back(make_pair(cnt, make_pair(start, j - 1)));
      start = j;
      cnt = range[j];
    }
  }
  v.push_back(make_pair(cnt, make_pair(start, n)));
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  sort(arr + 1, arr + n + 1);
  reverse(arr + 1, arr + n + 1);
  for (i = 2; i <= n; i++) {
    arr[i] += arr[i - 1];
  }
  long long sum = 0;
  start = 1;
  for (i = 0; i < v.size(); i++) {
    if (v[i].first != 0) {
      int siz = v[i].second.second - v[i].second.first;
      sum = sum + (long long)(v[i].first) * (arr[start + siz] - arr[start - 1]);
      start = start + siz + 1;
    }
  }
  cout << sum << endl;
  return 0;
}
