#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long double PI = 3.1415926535897932384626433832795;
long long int pwr(long long int b, long long int p) {
  long long int res = 1;
  while (p) {
    if (p & 1) {
      res *= b;
      p--;
    } else {
      b *= b;
      p >>= 1;
    }
  }
  return res;
}
long long int mpwr(long long int b, long long int p) {
  long long int res = 1;
  while (p) {
    if (p & 1) {
      res = (res * b) % MOD;
      p--;
    } else {
      b = (b * b) % MOD;
      p >>= 1;
    }
  }
  return res;
}
int msb(int n) { return 31 - __builtin_clz(n); }
long long int msbl(long long int n) { return 63 - __builtin_clzll(n); }
int lsb(int n) { return __builtin_ctz(n); }
long long int lsbl(long long int n) { return __builtin_ctzll(n); }
int setbit(int n) { return __builtin_popcount(n); }
long long int setbitl(long long int n) { return __builtin_popcountll(n); }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n, q;
  cin >> n >> q;
  vector<long long int> a(n), dif(n + 2, 0);
  for (int i = 0; i < n; i += 1) cin >> a[i];
  for (int i = 0; i < q; i += 1) {
    int l, r;
    cin >> l >> r;
    ++dif[l];
    --dif[r + 1];
  }
  for (int i = 1; i < n + 1; i += 1) dif[i] += dif[i - 1];
  vector<long long int> p;
  for (int i = 1; i < n + 1; i += 1) p.push_back(dif[i]);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  long long int ans = 0;
  int j = 0;
  for (auto pa : p) {
    ans += pa * a[j];
    ++j;
  }
  cout << ans << "\n";
  return 0;
}
