#include <bits/stdc++.h>
using namespace std;
const long double E = 2.71828182845904523536;
const long double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long oo = 1LL << 30;
void out(long long a[], long long n) {
  for (int i = 0; i <= n + 5; i++) cout << a[i] << "  ";
  cout << "\n";
}
void out(vector<long long> v) {
  for (auto a : v) cout << a << "  ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  auto start = chrono::steady_clock::now();
  long long n, q, x, y, ans = 0;
  cin >> n >> q;
  vector<long long> v(n, 0), u(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  while (q--) {
    cin >> x >> y;
    u[x - 1] += 1;
    u[y] -= 1;
  }
  for (int i = 1; i < n; i++) {
    u[i] += u[i - 1];
  }
  sort(v.begin(), v.end());
  sort(u.begin(), u.end() - 1);
  for (int i = 0; i < n; i++) {
    ans += v[i] * u[i];
  }
  cout << ans << "\n";
  auto end = chrono::steady_clock::now();
  return 0;
}
