#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  long long n, q;
  cin >> n >> q;
  long long a[n + 5], b[n + 5];
  memset(b, 0, sizeof(b));
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  while (q--) {
    long long l, r;
    cin >> l >> r;
    l--;
    r--;
    b[l]++;
    if (r < n - 1) b[r + 1]--;
  }
  for (int i = 1; i < n; i++) b[i] = b[i] + b[i - 1];
  sort(b, b + n);
  long long sum = 0;
  for (int i = 0; i < n; i++) sum += a[i] * b[i];
  cout << sum << endl;
}
