The little girl loves the problems on array queries very much.

One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive.

The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly.

The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements.

Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query.
#include<bits/stdc++.h>
#define int long long
#define fa(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define bp pop_back
#define mod 1000000007
#define mp make_pair
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define Utaval  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

void solve(){
    int n,q,tr=0,ct=0;
    cin>>n>>q;
    vector<int>v(n+2),temp(n+2),ans(n);
    vector<pair<int,int>>vp;
    fa(i,0,n)cin>>ans[i];
    sort(ans.begin(),ans.end(),greater<int>());
    vector<pair<int,int>>pq;
    fa(i,0,q){
        int x,y;
        cin>>x>>y;
        pq.pb({x,y});
        v[x]++,v[y+1]--;
    }
    fa(i,1,n+2)v[i]+=v[i-1];
    fa(i,1,n+1)vp.pb({v[i],i});
    sort(vp.begin(),vp.end(),greater<pair<int,int>>());
    fa(i,0,vp.size())temp[vp[i].second]=ans[tr++];
    fa(i,1,n+1)temp[i]+=temp[i-1];
    fa(i,0,pq.size())ct+=(temp[pq[i].second]-temp[pq[i].first-1]);
    cout<<ct<<endl;
    return;
}
signed main()
{
    Utaval;
    int t1=1;
    while(t1--)
    solve();
}
  	 			  	   			  	 	     	  	