#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <cctype>
#define len(c) sizeof(c)/4
#define print(c,n) for(int ix = 0; ix < n; ix++) cout <<c[ix]<<" ";cout<<endl;
#define MAXN 200000
#define N 800005
#define ll long long;
#define REP(i,a) for(int i=0;i<int(a);i++)
int A[MAXN];
int A2[MAXN];
int T[N];
using namespace std;
int LP[N];
void build(int node, int a, int b){
int m=(a+b)/2,r=node*2,l=node*2+1;
if(a==b){
T[node]=0;
return;
}
build(r, a,m);
build(l, m+1,b);
// for (int i=0; i<3; i++) {
// T[node][i] = T[node*2][i]+T[node*2+1][i];
// }
// T[node]=T[r]+T[l];
}
void push(int node, int a, int b){
int n=LP[node];
if(n>0){
if(a!=b){
LP[node*2]+=n;
LP[node*2+1]+=n;
}
T[node]+=LP[node];
LP[node]=0;
}
}
void update(int node, int a, int b, int i, int j){
int m=(a+b)/2,r=node*2,l=node*2+1;
push(node,a,b);
if(i>b || j<a)
return;
if(a>=i && b<=j){
LP[node]++;
return;
}
update(r, a,m,i,j);
update(l, m+1,b,i,j);
// T[node] = T[r]+T[l];
}
void query(int node, int a, int b){
int m=(a+b)/2,r=node*2,l=node*2+1;
push(node,a,b);
if(a==b){
A2[b]=T[node];
return;
}
query(r,a,m);
query(l,m+1,b);
}
int main()
{
// cout<<"xxx";
int n,q;
cin>>(n);
cin>>(q);
REP(i,n)scanf("%d",&A[i]);
sort(A,A+n);
// print(A,n);
for(int i=0;i<q;i++){
int a,b;
cin>>(a);
cin>>(b);
update(1, 0, n-1, a-1, b-1);
}
query(1,0,n-1);
sort(A2,A2+n);
long long r= 0;
for (int i =0; i<n; i++) {
r+=(long long)A[i]*(long long)A2[i];
}
cout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BpbnQgbT0oYStiKS8yLHI9bm9kZSoyLGw9bm9kZSoyKzE7CiAgICBpZihhPT1iKXsKICAgICAgICBUW25vZGVdPTA7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgYnVpbGQociwgYSxtKTsKICAgIGJ1aWxkKGwsIG0rMSxiKTsKICAgIC8vICAgIGZvciAoaW50IGk9MDsgaTwzOyBpKyspIHsKICAgIC8vICAgICAgICBUW25vZGVdW2ldID0gVFtub2RlKjJdW2ldK1Rbbm9kZSoyKzFdW2ldOwogICAgLy8gICAgfQovLyAgICBUW25vZGVdPVRbcl0rVFtsXTsKfQoKdm9pZCBwdXNoKGludCBub2RlLCBpbnQgYSwgaW50IGIpewogICAgaW50IG49TFBbbm9kZV07CiAgICBpZihuPjApewogICAgICAgIGlmKGEhPWIpewogICAgICAgICAgICBMUFtub2RlKjJdKz1uOwogICAgICAgICAgICBMUFtub2RlKjIrMV0rPW47CiAgICAgICAgfQogICAgICAgIFRbbm9kZV0rPUxQW25vZGVdOwogICAgICAgIExQW25vZGVdPTA7CiAgICB9Cn0KCnZvaWQgdXBkYXRlKGludCBub2RlLCBpbnQgYSwgaW50IGIsIGludCBpLCBpbnQgail7CiAgICBpbnQgbT0oYStiKS8yLHI9bm9kZSoyLGw9bm9kZSoyKzE7CiAgICBwdXNoKG5vZGUsYSxiKTsKICAgIGlmKGk+YiB8fCBqPGEpCiAgICAgICAgcmV0dXJuOwogICAgaWYoYT49aSAmJiBiPD1qKXsKICAgICAgICBMUFtub2RlXSsrOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIHVwZGF0ZShyLCBhLG0saSxqKTsKICAgIHVwZGF0ZShsLCBtKzEsYixpLGopOwovLyAgICBUW25vZGVdID0gVFtyXStUW2xdOwp9Cgp2b2lkIHF1ZXJ5KGludCBub2RlLCBpbnQgYSwgaW50IGIpewogICAgaW50IG09KGErYikvMixyPW5vZGUqMixsPW5vZGUqMisxOwogICAgcHVzaChub2RlLGEsYik7CiAgICBpZihhPT1iKXsKICAgICAgICBBMltiXT1UW25vZGVdOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIHF1ZXJ5KHIsYSxtKTsKICAgIHF1ZXJ5KGwsbSsxLGIpOwp9CgoKaW50IG1haW4oKQp7Ci8vICAgIGNvdXQ8PCJ4eHgiOwogICAgaW50IG4scTsKICAgIGNpbj4+KG4pOwogICAgY2luPj4ocSk7CiAgICBSRVAoaSxuKXNjYW5mKCIlZCIsJkFbaV0pOwogICAgc29ydChBLEErbik7Ci8vICAgIHByaW50KEEsbik7CiAgICBmb3IoaW50IGk9MDtpPHE7aSsrKXsKICAgICAgICAgICAgaW50IGEsYjsKICAgICAgICAgICAgY2luPj4oYSk7CiAgICAgICAgICAgIGNpbj4+KGIpOwogICAgICAgICAgICB1cGRhdGUoMSwgMCwgbi0xLCBhLTEsIGItMSk7CiAgICB9CiAgICBxdWVyeSgxLDAsbi0xKTsKICAgIHNvcnQoQTIsQTIrbik7CiAgICBsb25nIGxvbmcgcj0gMDsKICAgIGZvciAoaW50IGkgPTA7IGk8bjsgaSsrKSB7CiAgICAgICAgcis9KGxvbmcgbG9uZylBW2ldKihsb25nIGxvbmcpQTJbaV07CiAgICB9CiAgICBjb3V0PDxyOwogICAgcmV0dXJuIDA7Cn0KCg==