#include <bits/stdc++.h>
using namespace std;
void print_container(vector<long long> c) {
  cout << "[ ";
  for (int i = 0; i < c.size(); i++) cout << c[i] << ' ';
  cout << ']' << endl;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long ans = 0;
  long long n, q;
  cin >> n >> q;
  vector<long long> v(n, 0);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<long long> val(n, 0);
  for (long long i = 0; i < q; i++) {
    long long l, r;
    cin >> l >> r;
    val[l - 1]++;
    if (r < n) val[r]--;
  }
  for (long long i = 1; i < n; i++) {
    val[i] += val[i - 1];
  }
  sort(v.begin(), v.end());
  sort(val.begin(), val.end());
  for (long long i = 0; i < n; i++) {
    ans += v[i] * val[i];
  }
  cout << ans;
  return 0;
}
