#include <bits/stdc++.h>
using namespace std;
long long a[200005];
long long c[2][200005];
long long num[200005];
int n, m;
inline int lowbit(int x) { return x & -x; }
inline void update(int x, int val) {
  for (int i = x; i <= n; i += lowbit(i))
    c[0][i] += val, c[1][i] += (x - 1) * val;
}
inline long long query(int x) {
  long long sum1 = 0, sum2 = 0;
  for (int i = x; i > 0; i -= lowbit(i)) sum1 += c[0][i], sum2 += c[1][i];
  return x * sum1 - sum2;
}
bool cmp(long long a, long long b) { return a > b; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  while (m--) {
    int l, r;
    scanf("%d%d", &l, &r);
    update(r + 1, -1);
    update(l, 1);
  }
  for (int i = 1; i <= n; i++) {
    num[i] = query(i) - query(i - 1);
  }
  sort(a + 1, a + n + 1, cmp);
  sort(num + 1, num + n + 1, cmp);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += num[i] * a[i];
  }
  printf("%I64d\n", ans);
  return 0;
}
