#include <bits/stdc++.h>
using namespace std;
long long n, q;
long long a[1000005];
long long l, r;
long long f[1000005];
long long b[1000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> q;
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  while (q--) {
    cin >> l >> r;
    f[l - 1]++;
    f[r]--;
  }
  long long v = 0;
  for (long long i = 0; i < n; i++) {
    v += f[i];
    b[i] = v;
  }
  sort(b, b + n);
  long long res = 0;
  for (long long i = 0; i < n; i++) res += a[i] * b[i];
  cout << res;
  return 0;
}
