#include <bits/stdc++.h>
using namespace std;
const long long C = 1000000007;
const long long N = 200005;
int main() {
  ios::sync_with_stdio(0);
  int n, q, l, r;
  int nums[N];
  int counts[N];
  long long result = 0;
  memset(counts, 0, sizeof(counts));
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    cin >> nums[i];
  }
  sort(nums, nums + n);
  for (int i = 0; i < q; ++i) {
    cin >> l >> r;
    counts[l - 1] += 1;
    counts[r] -= 1;
  }
  for (int i = 1; i < n; ++i) {
    counts[i] += counts[i - 1];
  }
  sort(counts, counts + n);
  for (int i = 0; i < n; ++i) {
    result += (long long)counts[i] * nums[i];
  }
  cout << result << endl;
}
