#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010];
int main() {
  int n, q, i, l, r;
  long long ans = 0;
  cin >> n >> q;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  while (q--) {
    scanf("%d%d", &l, &r);
    b[l]++;
    b[r + 1]--;
  }
  for (i = 1; i <= n; i++) b[i] += b[i - 1];
  sort(b + 1, b + n + 1);
  for (i = 1; i <= n; i++) ans += (long long)(a[i]) * b[i];
  cout << ans << endl;
  return 0;
}
