#include <bits/stdc++.h>
using namespace std;
long long d[200001];
long long tree[200001];
int n, m;
void Update(int x, int val) {
  while (x <= n) {
    tree[x] += val;
    x += (x & (-x));
  }
}
long long Quary(int x) {
  long long cnt = 0;
  while (x > 0) {
    cnt += tree[x];
    x -= (x & (-x));
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  priority_queue<long long> q;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    q.push(x);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    Update(x, 1);
    Update(y + 1, -1);
  }
  long long ans = 0;
  vector<long long> v;
  for (int i = 1; i <= n; i++) {
    v.push_back(Quary(i));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    ans += (v[i] * q.top());
    q.pop();
  }
  cout << ans << '\n';
}
