#include <bits/stdc++.h>
using namespace std;
long long int dp[200005];
long long int val[200005];
void solve() {
  long long int n, q;
  cin >> n >> q;
  for (long long int i = 0; i < n; i++) {
    cin >> val[i];
  }
  memset(dp, 0, sizeof dp);
  while (q--) {
    long long int l, r;
    cin >> l >> r;
    dp[r + 1]--;
    dp[l]++;
  }
  for (long long int i = 1; i <= n; i++) {
    dp[i] = dp[i] + dp[i - 1];
  }
  sort(dp, dp + n + 1);
  sort(val, val + n);
  long long int fuckanshul = 0;
  for (long long int i = 1; i <= n; i++) {
    fuckanshul += dp[i] * (val[i - 1]);
  }
  cout << fuckanshul << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tests = 1;
  while (tests--) {
    solve();
  }
}
