#include <bits/stdc++.h>
using namespace std;
int n, m, arr[(int)2e5 + 5], x[(int)2e5 + 5], y[(int)2e5 + 5];
pair<int, int> ordr[(int)2e5 + 5];
long long res[(int)2e5 + 5], ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", arr + i);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", x + i, y + i);
    ordr[x[i]].first += 1, ordr[y[i] + 1].first += -1;
  }
  for (int i = 1; i <= n; ++i)
    ordr[i].first += ordr[i - 1].first, ordr[i].second = i;
  sort(arr + 1, arr + n + 1);
  reverse(arr + 1, arr + n + 1);
  sort(ordr + 1, ordr + n + 1);
  reverse(ordr + 1, ordr + n + 1);
  for (int i = 1; i <= n; ++i) res[ordr[i].second] = arr[i];
  for (int i = 1; i <= n; ++i) res[i] += res[i - 1];
  for (int i = 0; i < m; ++i) ans += res[y[i]] - res[x[i] - 1];
  printf("%I64d\n", ans);
  return 0;
}
