#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int lcm(int fir, int sec) { return (fir * sec) / (gcd(fir, sec)); }
int modularExponentiation(int x, int n, int M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % M, n / 2, M);
  else
    return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
const int MOD = 1e6 + 7;
const string smaint_alphabets = "abcdefghijklmnopqrstuvwxyz";
const int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long int arr[200008];
long long int pre[200008];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, q;
  cin >> n >> q;
  memset(pre, 0, sizeof pre);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long long int x, y;
  for (int i = 0; i < q; ++i) {
    cin >> x >> y;
    x--;
    y--;
    pre[x]++;
    pre[y + 1]--;
  }
  for (int i = 1; i < n; ++i) {
    pre[i] += pre[i - 1];
  }
  sort(pre, pre + n);
  long long int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += (1LL * arr[i] * pre[i]);
  }
  cout << ans << endl;
  return 0;
}
