#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-7;
const long long int mod = 1000000007;
void solve() {
  long long int n, q, out = 0;
  cin >> n >> q;
  vector<long long int> a(n), prefix_sum(n + 2, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  while (q--) {
    int l, r;
    cin >> l >> r;
    prefix_sum[l]++;
    prefix_sum[r + 1]--;
  }
  for (int i = 1; i < n + 1; i++) {
    prefix_sum[i] += prefix_sum[i - 1];
  }
  sort(prefix_sum.begin(), prefix_sum.end(), greater<int>());
  int i = 0;
  while (prefix_sum[i] > 0) {
    out += prefix_sum[i] * a[i];
    i++;
  }
  cout << out << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
