#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
long long arr[N], val[N], tree[N];
int vis[N];
int n, q, l, r, tk;
void addvalue(int index, long long value) {
  while (index <= n) {
    tree[index] += value, index += (index & -index);
  }
}
int getAccum(int idx) {
  int sum = 0;
  while (idx > 0) sum += tree[idx], idx -= (idx & -idx);
  return sum;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    scanf("%d", val + i);
  }
  while (q--) {
    scanf("%d%d", &l, &r);
    addvalue(l, 1);
    addvalue(r + 1, -1);
  }
  for (int i = 1; i <= n; ++i) {
    arr[i - 1] = getAccum(i);
  }
  sort(val, val + n);
  sort(arr, arr + n);
  unsigned long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans += arr[i] * val[i];
  }
  cout << ans;
}
