#include <bits/stdc++.h>
using namespace std;
int n, q, arr[200009], m[200009], l[200009], r[200009];
long long ans, newarr[200009];
vector<pair<int, int>> vp;
bool preceed(int x, int y) { return x > y; }
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  sort(arr, arr + n, preceed);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &l[i], &r[i]);
    m[l[i] - 1]++;
    m[r[i]]--;
  }
  for (int i = 1; i < n; i++) m[i] += m[i - 1];
  for (int i = 0; i < n; i++) vp.push_back(make_pair(m[i], i));
  sort(vp.rbegin(), vp.rend());
  int k = 0;
  for (auto i : vp) {
    newarr[i.second] = arr[k];
    k++;
  }
  for (int i = 1; i < n; i++) newarr[i] += newarr[i - 1];
  for (int i = 0; i < q; i++) ans += (newarr[r[i] - 1] - newarr[l[i] - 2]);
  printf("%I64d", ans);
  return 0;
}
