#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  long long n, q;
  cin >> n >> q;
  long long* m = (long long*)malloc((n + 2) * sizeof(long long));
  for (int i = 0; i < n + 2; i++) {
    m[i] = 0;
  }
  long long* num = (long long*)malloc(n * sizeof(long long));
  for (int i = 0; i < n; i++) cin >> num[i];
  while (q--) {
    long long a, b;
    cin >> a >> b;
    b++;
    m[a]++;
    m[b]--;
  }
  for (int i = 1; i < n + 2; i++) m[i] += m[i - 1];
  sort(num, num + n);
  sort(m + 1, m + n + 1);
  long long answer = 0;
  for (int i = 0; i < n; i++) {
    answer += num[i] * m[i + 1];
  }
  cout << answer << endl;
  return 0;
}
