#include <bits/stdc++.h>
using namespace std;
long long a[1000001], prefix[1000001], b[1000001];
std::vector<pair<long long, long long> > v, query;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, i, j, q, sum = 0;
  cin >> n >> q;
  for (i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (i = 0; i < q; ++i) {
    long long l, r;
    cin >> l >> r;
    prefix[l]++;
    prefix[r + 1]--;
    query.push_back(make_pair(l - 1, r));
  }
  v.push_back(make_pair(prefix[1], 1));
  for (i = 2; i <= n; ++i) {
    prefix[i] += prefix[i - 1];
    v.push_back(make_pair(prefix[i], i));
  }
  sort(v.begin(), v.end());
  for (i = 0; i < v.size(); ++i) {
    b[v[i].second] = a[i + 1];
  }
  for (i = 2; i <= n; ++i) b[i] += b[i - 1];
  for (i = 0; i < query.size(); ++i) {
    sum += (b[query[i].second] - b[query[i].first]);
  }
  cout << sum;
}
