#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long a, b, c, d;
  cin >> a >> b;
  vector<long long> g(a), v(a + 1), vv(a);
  for (int i = 0; i < a; i++) {
    cin >> g[i];
    v[i] = 0;
    vv[i] = 0;
  }
  for (int i = 0; i < b; i++) {
    cin >> c >> d;
    c--;
    d--;
    v[c]++;
    v[d + 1]--;
  }
  vv[0] = v[0];
  for (int i = 1; i < a; i++) {
    vv[i] = vv[i - 1] + v[i];
  }
  sort(g.begin(), g.end());
  sort(vv.begin(), vv.end());
  d = 0;
  for (int i = 0; i < a; i++) {
    d += vv[i] * g[i];
  }
  cout << d;
}
