#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  long long arr[n], ans[n + 2];
  memset(ans, 0, sizeof ans);
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  vector<pair<int, int> > p, v;
  int x, y;
  for (int i = 1; i <= q; i++) {
    cin >> x >> y;
    ans[x] += 1;
    ans[y + 1] -= 1;
    p.push_back({x, y});
  }
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    cnt += ans[i];
    v.push_back({cnt, i});
  }
  sort(v.rbegin(), v.rend());
  ans[0] = 0;
  for (int i = 0, j = n - 1; i < n; i++, j--) {
    ans[v[i].second] = arr[j];
  }
  for (int i = 1; i <= n; i++) ans[i] += ans[i - 1];
  cnt = 0;
  for (int i = 0; i < q; i++) cnt += ans[p[i].second] - ans[p[i].first - 1];
  cout << cnt;
  return 0;
}
