#include <bits/stdc++.h>
int main() {
  size_t n, q;
  std::cin >> n >> q;
  std::vector<int32_t> a(n);
  for (int i = 0; i < n; i++) std::cin >> a[i];
  std::vector<int32_t> freq(n + 1, 0);
  for (int i = 0; i < q; i++) {
    int l, r;
    std::cin >> l >> r;
    freq[l - 1] += 1;
    freq[r] -= 1;
  }
  for (int i = 1; i < n; i++) freq[i] += freq[i - 1];
  sort(a.begin(), a.end(), std::greater<int32_t>());
  sort(freq.begin(), freq.end() - 1, std::greater<int32_t>());
  int64_t max_sum = 0, i = 0;
  while (i < n and freq[i] != 0) {
    max_sum += ((int64_t)a[i]) * ((int64_t)freq[i]);
    i++;
  }
  std::cout << max_sum << std::endl;
  return 0;
}
