#include <bits/stdc++.h>
using namespace std;
const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},
                       {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
#pragma unused(fx)
#pragma unused(fxx)
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int i = 0; i < (t).size(); i++)
    s << t[i] << ((i < (t).size() - 1) ? " " : "");
  return s;
}
int main() {
  int(n), (q);
  scanf("%d %d", &(n), &(q));
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int(x);
    scanf("%d", &(x));
    a.push_back(x);
  };
  vector<int> count(n), t(n);
  for (int i = 0; i < q; i++) {
    int(l), (r);
    scanf("%d %d", &(l), &(r));
    t[l - 1] += 1;
    if (r < n) t[r] -= 1;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0)
      count[i] = t[0];
    else
      count[i] = count[i - 1] + t[i];
  }
  sort((count).begin(), (count).end());
  sort((a).begin(), (a).end());
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += ((long long)count[i]) * a[i];
  }
  cout << sum;
}
