import java.util.*;
import java.util.regex.*;
import static java.
lang.
Math.
*; import static java.
util.
Arrays.
*; import static java.
lang.
Double.
*; import java.io.*;
public class _C {
public void solve() {
int N = in.nextInt();
// int N = 200000;
int Q = in.nextInt();
// int Q = 200000;
int [] a=new int[N];
for (int i = 0; i < a.length; i++) {
a[i]=in.nextInt();
// a[i]=i+;
}
T = new long[N*4];
lp = new long[N*4];
a2=new long[N];
for (int i = 0; i < Q; i++) {
int l=in.nextInt()-1;
int r=in.nextInt()-1;
// int l = i;
// int r=i+1;
// print(l,r);
update(1,0,N-1,l,r);
}
// int xx = 40000000000;
query(1,0,N-1);
sort(a);
sort(a2);
long r=0;
for (int i = 0; i < a.length; i++) {
r+=((long)a[i])*a2[i];
}
// print(a,a2);
}
long a2[];
long[]T;
long[]lp;
void query(int node, int a, int b){
push(node, a, b);
if(a==b){
a2[b]=T[node];
return;
}
int l=node*2,r=l+1,mid=(a+b)>>1;
query(l,a,mid);
query(r,mid+1,b);
// T[node]=T[l]+T[r];
}
void push(int node , int a, int b){
if(lp[node]>0){
int l=node*2,r=l+1;
if(a!=b){
lp[l]+=lp[node];
lp[r]+=lp[node];
}
T[node]+=lp[node];
lp[node]=0;
}
}
void update(int node, int a, int b, int i, int j){
if(a>b || i>b || a>j)
return;
// print(node, a, b, mid, i, j);
// push(node, a, b);
if(a>=i && b<=j){
lp[node]++;
// push(node, a, b);
return;
}
int l=node*2,r=l+1,mid=(a+b)>>1;
update(l,a,mid,i,j);
update(r,mid+1,b,i,j);
// T[node]=T[l]+T[r];
}
_C(){
}
public static void close(){
in.close();
out.close();
}
new _C().solve();
close();
}
static Scanner in;
static int readInt(){
return in.nextInt();
// return parseInt(in.nextLine());
}
static int[] readIntArray(){
String l
[] = in.
next().
split(" "); int[] r=new int[l.length];
for (int i = 0; i < l.length; i++) {
r[i]=parseInt(l[i]);
}
return r;
}
static void print
(Object...
ob) { System.
out.
println(Arrays.
deepToString(ob
).
replace("],",
"],\n")); }
}
CgppbXBvcnQg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