#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int d[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  int a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i];
  pair<int, int> q[k];
  for (int i = 0; i < k; i++) {
    cin >> q[i].first >> q[i].second;
    d[q[i].first]++;
    d[q[i].second + 1]--;
  }
  for (int i = 1; i <= n; i++) d[i] += d[i - 1];
  sort(a + 1, a + (n + 1));
  sort(d + 1, d + (n + 1));
  long long int sum = 0;
  for (int i = 1; i <= n; i++) sum += (long long)a[i] * d[i];
  cout << sum;
}
