#include <bits/stdc++.h>
using namespace std;
int n;
int q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  vector<int> heat_track(n);
  vector<int> heat(n);
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int e;
    cin >> e;
    a.push_back(e);
  }
  int as = a.size();
  int l;
  int r;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    if (r < as) {
      heat_track[r + 1 - 1]--;
    }
    heat_track[l - 1]++;
  }
  int su = 0;
  for (int i = 0; i < as; i++) {
    su += heat_track[i];
    heat[i] = su;
  }
  sort(heat.begin(), heat.end());
  sort(a.begin(), a.end());
  long long s = 0;
  for (int i = 0; i < n; i++) {
    s += ((long long)1 * heat[i] * a[i]);
  }
  cout << s;
}
