#include <bits/stdc++.h>
using namespace std;
long long zero = 0;
long long one = 1;
long long MAX_SIZE_5 = 100005;
long long MAX_SIZE_6 = 1000005;
long long max_ll = LLONG_MAX;
long long min_ll = LLONG_MIN;
int max_int = INT_MAX;
int min_int = INT_MIN;
long long mod = 1000000007;
long long my_pow(long long a, long long b, long long m = mod) {
  if (b == 0) {
    return 1 % m;
  }
  if (b == 1) {
    return a % m;
  }
  long long temp = my_pow(a, b / 2, m);
  if (b % 2 == 0) {
    return (temp * temp) % m;
  } else {
    return (((temp * temp) % m) * a) % m;
  }
}
long long mod_inv(long long x, long long m = mod) {
  return my_pow(x, m - 2, m);
}
void solve() {
  long long n, q;
  cin >> n >> q;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<long long> opening(n, 0);
  vector<long long> closing(n, 0);
  long long l, r;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    l--;
    r--;
    opening[l]++;
    closing[r]++;
  }
  long long cur = 0;
  vector<long long> cnt(n, 0);
  for (int i = 0; i < n; i++) {
    cur += opening[i];
    cnt[i] = cur;
    cur -= closing[i];
  }
  sort(cnt.begin(), cnt.end(), greater<long long>());
  sort(a.begin(), a.end(), greater<long long>());
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += (a[i] * cnt[i]);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
