#include <bits/stdc++.h>
using namespace std;
long long bit[(long long)2e5 + 100];
void update(long long idx, long long val, long long n) {
  while (idx <= n) {
    bit[idx] += val;
    idx += idx & -idx;
  }
}
long long pref(long long idx) {
  long long ans = 0;
  while (idx > 0) {
    ans += bit[idx];
    idx -= idx & -idx;
  }
  return ans;
}
signed main() {
  long long n, m;
  cin >> n >> m;
  priority_queue<long long> a, b;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long v;
    cin >> v;
    a.push(v);
  }
  for (long long i = 1; i <= m; i++) {
    long long l, r;
    cin >> l >> r;
    update(l, 1, n);
    update(r + 1, -1, n);
  }
  for (long long i = 1; i <= n; i++) {
    b.push(pref(i));
  }
  while (!a.empty()) {
    ans += a.top() * b.top();
    a.pop();
    b.pop();
  }
  cout << ans << '\n';
  return 0;
}
