#include <bits/stdc++.h>
using namespace std;
int a[100111 * 2];
long long f[100111 * 2], dodanie[100111 * 2];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  long long ans = 0;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0, a, b; i < q; ++i) {
    cin >> a >> b;
    ++dodanie[a - 1];
    --dodanie[b];
  }
  f[0] = dodanie[0];
  for (int i = 0; i <= n; ++i) f[i] = f[i - 1] + dodanie[i];
  sort(f, f + n);
  sort(a, a + n);
  reverse(f, f + n);
  reverse(a, a + n);
  for (int i = 0; i < n; ++i) ans += a[i] * f[i];
  cout << ans << "\n";
}
