#include <bits/stdc++.h>
using namespace std;
int n, m;
int bit[200002], A[200002], c[200002];
int a, b;
void update(int x, int val) {
  for (; x <= n; x += (x & -x)) bit[x] += val;
}
int query(int x) {
  int ret = 0;
  for (; x; x -= (x & -x)) ret += bit[x];
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> A[i];
  sort(A + 1, A + n + 1);
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    update(a, 1);
    update(b + 1, -1);
  }
  for (int i = 1; i <= n; i++) c[i] = query(i);
  sort(c + 1, c + n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    ans += (long long int)(A[i]) * (long long int)(c[i]);
  cout << ans << "\n";
  return 0;
}
