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