#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, q;
  int first, last;
  long long result;
  vector<int> values;
  vector<int> left, right, queries;
  int current;
  cin >> n >> q;
  queries.resize(n);
  values.resize(n);
  left.resize(n);
  right.resize(n);
  for (int i = 0; i < n; i++) {
    queries[i] = 0;
    left[i] = 0;
    right[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> values[i];
  }
  for (int i = 0; i < q; i++) {
    cin >> first >> last;
    left[first - 1]++;
    right[last - 1]++;
  }
  current = 0;
  for (int i = 0; i < n; i++) {
    current += left[i];
    if (i > 0) current -= right[i - 1];
    queries[i] = current;
  }
  sort(queries.begin(), queries.end());
  sort(values.begin(), values.end());
  result = 0;
  for (int i = 0; i < n; i++) {
    result += ((long long)queries[i]) * ((long long)values[i]);
  }
  cout << result << endl;
}
