#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int maxN = 200 * 1000 + 9;
int n, q;
long long a[maxN];
long long fwt[maxN], h[maxN];
void read() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
}
void upd(int idx, long long v) {
  for (; idx <= n; idx += idx & -idx) fwt[idx] += v;
}
long long getSum(int idx) {
  long long total = 0;
  for (; idx > 0; idx -= idx & -idx) total += fwt[idx];
  return total;
}
void solv() {
  while (q--) {
    int l, r;
    cin >> l >> r;
    upd(l, 1);
    upd(r + 1, -1);
  }
  for (int i = 1; i <= n; i++) h[i] = getSum(i);
  sort(h + 1, h + n + 1);
  sort(a + 1, a + n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += h[i] * a[i];
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  read();
  solv();
  return 0;
}
