#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long b) {
  if (b == 0) return 1;
  long long res = binpow(a, b / 2);
  res = (res * res) % 1000000007LL;
  if (b % 2) {
    res = (res * a) % 1000000007LL;
  }
  return res;
}
long long inv(long long n) { return binpow(n, 1000000007LL - 2); }
bool compare(const pair<long long, long long>& i,
             const pair<long long, long long>& j) {
  if (i.first != j.first)
    return i.first < j.first;
  else
    return i.second > j.second;
}
vector<long long> factorize(long long n) {
  vector<long long> v;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      v.push_back(i);
      n /= i;
    }
  }
  if (n != 1) v.push_back(n);
  return v;
}
long long nCrModpDP(long long n, long long r) {
  long long C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = min(i, r); j > 0; j--)
      C[j] = (C[j] + C[j - 1]) % 1000000007LL;
  }
  return C[r];
}
long long binomialCoefficient(long long n, long long r) {
  if (r == 0) return 1;
  long long ni = n % 1000000007LL, ri = r % 1000000007LL;
  return (binomialCoefficient(n / 1000000007LL, r / 1000000007LL) *
          nCrModpDP(ni, ri)) %
         1000000007LL;
}
vector<bool> sieve(long long n) {
  vector<bool> PRIME(n + 1, true);
  PRIME[0] = false;
  PRIME[1] = false;
  for (long long p = 2; p * p <= n; p++) {
    if (PRIME[p] == true) {
      for (long long i = p * p; i <= n; i += p) {
        PRIME[i] = false;
      }
    }
  }
  return PRIME;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, q, a, b, ans = 0;
  cin >> n >> q;
  vector<long long> v(n + 1, 0), vec;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    vec.push_back(a);
  }
  sort(vec.rbegin(), vec.rend());
  while (q--) {
    cin >> a >> b;
    v[a - 1] += 1;
    v[b] += (-1);
  }
  for (long long i = 1; i < v.size(); i++) v[i] += v[i - 1];
  sort(v.rbegin(), v.rend());
  for (long long i = 0; i < n; i++) ans += (vec[i] * v[i]);
  cout << ans;
}
