#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int MAX_N = 200000;
int t[4 * MAX_N];
int n;
void add(int x, int l, int r, int v = 1, int tl = 0, int tr = n - 1) {
  if (tl == l && tr == r) {
    t[v] += x;
    return;
  }
  int tm = (tl + tr) / 2;
  if (r <= tm) {
    add(x, l, r, 2 * v, tl, tm);
    return;
  }
  if (l > tm) {
    add(x, l, r, 2 * v + 1, tm + 1, tr);
    return;
  }
  add(x, l, tm, 2 * v, tl, tm);
  add(x, tm + 1, r, 2 * v + 1, tm + 1, tr);
}
int el(int i, int v = 1, int tl = 0, int tr = n - 1) {
  if (tl == tr) {
    return t[v];
  }
  int tm = (tl + tr) / 2;
  if (i <= tm) {
    return el(i, 2 * v, tl, tm) + t[v];
  }
  return el(i, 2 * v + 1, tm + 1, tr) + t[v];
}
int main() {
  int q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    add(1, l, r);
  }
  vector<int> count(n);
  for (int i = 0; i < n; ++i) {
    count[i] = el(i);
  }
  sort(count.begin(), count.end());
  sort(a.begin(), a.end());
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    res += (long long)a[i] * (long long)count[i];
  }
  cout << res << endl;
  return 0;
}
