#include <bits/stdc++.h>
using namespace std;
long long qpow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2) {
      res = (res * a) % 100000007;
      n--;
    } else {
      n = n / 2;
      a = (a * a) % 100000007;
    }
  }
  return res;
}
void solve() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, q;
  cin >> n >> q;
  vector<long long> arr(n + 1);
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  vector<long long> H(n + 1);
  for (long long i = 0; i < q; i++) {
    long long l, r;
    cin >> l >> r;
    H[l]++;
    if (r + 1 <= n) H[r + 1]--;
  }
  for (long long i = 1; i <= n; i++) H[i] += H[i - 1];
  sort(H.begin() + 1, H.end());
  sort(arr.begin() + 1, arr.end());
  long long sum = 0;
  for (long long i = 1; i <= n; i++) sum += H[i] * arr[i];
  cout << sum << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
