#include <bits/stdc++.h>
using namespace std;
long long a[200002];
int a_adder[200002];
long long q_count[200002];
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i];
  int l, r;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    l -= 1;
    r -= 1;
    a_adder[l] += 1;
    a_adder[r + 1] -= 1;
  }
  int adder = 0;
  for (int i = 0; i < n; i++) {
    adder += a_adder[i];
    q_count[i] = adder;
  }
  sort(q_count, q_count + n);
  sort(a, a + n);
  long long summ = 0;
  for (int i = 0; i < n; i++) {
    summ += a[i] * q_count[i];
  }
  cout << summ << endl;
}
