#include <bits/stdc++.h>
using namespace std;
const double EPS = pow(10, -10);
const long long INF = 1e9;
const long long MOD = pow(10, 9) + 7;
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
int main() {
  ios_base::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<long long> a(n);
  vector<long long> freq(n + 2);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int l, r;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    freq[l]++;
    freq[r + 1]--;
  }
  int cur = 0;
  for (int i = 1; i <= n; i++) {
    cur = cur + freq[i];
    freq[i] = cur;
  }
  sort(freq.begin(), freq.end());
  reverse(freq.begin(), freq.end());
  unsigned long long ans = 0;
  int j = 0;
  for (int i = 0; i < n; i++) {
    ans = ans + freq[i] * a[j];
    j++;
  }
  cout << ans;
  return 0;
}
