#include <bits/stdc++.h>
using namespace std;
int n, q, x, y;
long long ret = 0LL;
long long niz[300001];
long long new_niz[300001];
long long tree[300001];
void update(int x, long long val) {
  while (x <= n) {
    tree[x] += val;
    x += (x & -x);
  }
}
long long read(int x) {
  int sum = 0;
  while (x > 0) {
    sum += tree[x];
    x -= (x & -x);
  }
  return sum;
}
int main() {
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> niz[i];
  sort(niz, niz + n);
  while (q--) {
    cin >> x >> y;
    update(x, 1);
    update(y + 1, -1);
  }
  for (int i = 1; i <= n; i++) {
    new_niz[i - 1] = read(i);
  }
  sort(new_niz, new_niz + n);
  for (int i = n - 1; i >= 0; i--) {
    ret += niz[i] * new_niz[i];
  }
  cout << ret << endl;
  return 0;
}
