#include <bits/stdc++.h>
using namespace std;
long long tree[1000000] = {0};
long long lazy[1000000] = {0};
void updateRange(int node, int start, int end, int l, int r, long long val) {
  if (lazy[node] != 0) {
    tree[node] += (end - start + 1) * lazy[node];
    if (start != end) {
      lazy[node * 2] += lazy[node];
      lazy[node * 2 + 1] += lazy[node];
    }
    lazy[node] = 0;
  }
  if (start > end or start > r or end < l) return;
  if (start >= l and end <= r) {
    tree[node] += (end - start + 1) * val;
    if (start != end) {
      lazy[node * 2] += val;
      lazy[node * 2 + 1] += val;
    }
    return;
  }
  int mid = (start + end) / 2;
  updateRange(node * 2, start, mid, l, r, val);
  updateRange(node * 2 + 1, mid + 1, end, l, r, val);
  tree[node] = tree[node * 2] + tree[node * 2 + 1];
}
long long queryRange(int node, int start, int end, int l, int r) {
  if (start > end or start > r or end < l) return 0;
  if (lazy[node] != 0) {
    tree[node] += (end - start + 1) * lazy[node];
    if (start != end) {
      lazy[node * 2] += lazy[node];
      lazy[node * 2 + 1] += lazy[node];
    }
    lazy[node] = 0;
  }
  if (start >= l and end <= r) return tree[node];
  int mid = (start + end) / 2;
  long long p1 = queryRange(node * 2, start, mid, l, r);
  long long p2 = queryRange(node * 2 + 1, mid + 1, end, l, r);
  return (p1 + p2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long m;
  cin >> m;
  priority_queue<long long> pq;
  long long temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    pq.push(temp);
  }
  for (int i = 0; i < m; i++) {
    long long l, r;
    cin >> l >> r;
    updateRange(1, 0, n - 1, l - 1, r - 1, 1);
  }
  long long ans = 0;
  priority_queue<long long> pq2;
  for (int i = 0; i < n; i++) {
    pq2.push(queryRange(1, 0, n - 1, i, i));
  }
  for (int i = 0; i < n; i++) {
    ans += pq.top() * pq2.top();
    pq.pop();
    pq2.pop();
  }
  cout << ans;
}
