#include <bits/stdc++.h>
using namespace std;
long long v[1000000];
int main() {
  int n, q, x, y;
  long long sum = 0;
  cin >> n >> q;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    v[x]++;
    v[y + 1]--;
  }
  for (int i = 1; i <= n; i++) v[i] += v[i - 1];
  sort(v, v + n + 1);
  sort(a.begin(), a.end());
  for (int i = 1; i <= n; i++) sum += a[i - 1] * v[i];
  cout << sum;
  return 0;
}
