#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE = 2 * 100000 + 10;
long long t[MAX_SIZE], s;
int main() {
  int n, q, l, r;
  int arr[MAX_SIZE];
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> arr[i], t[i] = 0;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    t[l - 1]++, t[r]--;
  }
  for (int i = 0; i < n; i++) s += t[i], t[i] = s;
  sort(t, t + n);
  sort(arr, arr + n);
  long long sum = 0;
  for (int i = 0; i < n; i++) sum += (long long)t[i] * arr[i];
  cout << sum;
  return 0;
}
