#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long fen[N];
long long a[N];
long long freq[N];
int n, q;
void update(int idx, long long val) {
  while (idx <= n) {
    fen[idx] += val;
    idx += idx & -idx;
  }
}
long long query(int idx) {
  long long sum = 0;
  while (idx > 0) {
    sum += fen[idx];
    idx -= idx & -idx;
  }
  return sum;
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  reverse(a + 1, a + 1 + n);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    update(l, 1);
    update(r + 1, -1);
  }
  priority_queue<long long> pq;
  for (int i = 1; i <= n; i++) {
    pq.push(query(i));
  }
  long long sum = 0;
  int i = 1;
  while (not pq.empty() and i <= n) {
    sum += pq.top() * a[i];
    pq.pop(), i++;
  }
  printf("%lld\n", sum);
  return 0;
}
