#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, add;
  node *left, *right;
};
node* build(int l, int r) {
  node* root = new node;
  root->l = l;
  root->r = r;
  if (l == r) {
    root->left = root->right = 0;
    root->add = 0;
  } else {
    root->add = 0;
    int mid = (l + r) / 2;
    root->left = build(l, mid);
    root->right = build(mid + 1, r);
  }
  return root;
}
void add(node* root, int l, int r) {
  if (l > root->r || r < root->l) return;
  if (l <= root->l && r >= root->r) {
    root->add++;
    return;
  }
  add(root->left, l, r);
  add(root->right, l, r);
}
int query(node* root, int i) {
  if (i < root->l || i > root->r) return 0;
  if (root->l == root->r) return root->add;
  int ans1 = query(root->left, i), ans2 = query(root->right, i);
  return ans1 + ans2 + root->add;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  node* root = build(0, n - 1);
  for (int ts = 0; ts < q; ++ts) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    add(root, l, r);
  }
  vector<int> v(n);
  for (int i = 0; i < n; ++i) v[i] = query(root, i);
  sort(v.rbegin(), v.rend());
  sort(a.rbegin(), a.rend());
  long long res = 0;
  for (int i = 0; i < n; ++i) res += (long long)v[i] * a[i];
  cout << res << endl;
  return 0;
}
