#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128777216")
const long long LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;
using namespace std;
void prepare(string s) {
  if (s.length() != 0) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
  }
}
const int NMAX = 200010;
vector<long long> v(NMAX), g(NMAX), p(NMAX);
int main() {
  prepare("");
  long long n = 0, q = 0, l = 0, r = 0;
  cin >> n >> q;
  for (int i = 0; i < (int)n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < (int)q; i++) {
    cin >> l >> r;
    g[l - 1]++;
    g[r]--;
  }
  for (int i = (int)1; i <= (int)n; i++) {
    g[i] += g[i - 1];
  }
  long long sum = 0;
  sort(v.begin(), v.begin() + n);
  sort(g.begin(), g.begin() + n);
  for (int i = (int)n - 1; i >= 0; i--) {
    sum += v[i] * g[i];
  }
  cout << sum;
  return 0;
}
