#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 2e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
inline int read_int() {
  char c;
  int ret = 0, sgn = 1;
  do {
    c = getchar();
  } while ((c < '0' || c > '9') && c != '-');
  if (c == '-')
    sgn = -1;
  else
    ret = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  return sgn * ret;
}
inline long long read_ll() {
  char c;
  long long ret = 0, sgn = 1;
  do {
    c = getchar();
  } while ((c < '0' || c > '9') && c != '-');
  if (c == '-')
    sgn = -1;
  else
    ret = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  return sgn * ret;
}
int arr[4 * maxn + 5], a[maxn + 5], cnt[maxn + 5], q, l, r, n;
long long res;
inline void Push_Down(int index) {
  arr[2 * index] += arr[index];
  arr[2 * index + 1] += arr[index];
  arr[index] = 0;
}
void Update(int index, int L, int R, int UL, int UR) {
  if (L >= UL && R <= UR) {
    arr[index] += 1;
    return;
  }
  if (arr[index]) Push_Down(index);
  int mid = L + R >> 1;
  if (mid >= UL) Update(2 * index, L, mid, UL, UR);
  if (UR > mid) Update(2 * index + 1, mid + 1, R, UL, UR);
}
int Query(int index, int L, int R, int pos) {
  if (L == R) return arr[index];
  if (arr[index]) Push_Down(index);
  int mid = L + R >> 1;
  if (mid >= pos)
    return Query(2 * index, L, mid, pos);
  else
    return Query(2 * index + 1, mid + 1, R, pos);
}
int main() {
  n = read_int(), q = read_int();
  for (int i = 1; i <= n; ++i) a[i] = read_int();
  while (q--) {
    l = read_int(), r = read_int();
    Update(1, 1, n, l, r);
  }
  for (int i = 1; i <= n; ++i) cnt[i] = Query(1, 1, n, i);
  sort(a + 1, a + 1 + n, greater<int>());
  sort(cnt + 1, cnt + 1 + n, greater<int>());
  for (int i = 1; i <= n; ++i) res += 1ll * a[i] * cnt[i];
  printf("%I64d\n", res);
  return 0;
}
