#include<algorithm>
#include<iostream>
#include<sstream>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<fstream>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
using namespace std;

#define pb push_back
#define mp make_pair
#define Y second
#define X first

#define fi freopen("input.txt","r",stdin)
#define fo freopen("output.txt","w",stdout)

const double pi     =   acos(-1.0);
const double eps    =   1e-8;

template <class T>
inline void read(T &i)
{
bool minus=false;
char c;
for(c=getchar();(c<'0'||c>'9')&&(c!='-');c=getchar());
if(c=='-')
{minus=true;
c='0';}
for(i=0;c>='0'&&c<='9';c=getchar())
i=(i<<3)+(i<<1) + (c-48);
if(minus)
i=(~i)+1;
}

vector <string> parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  vector <string> ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

inline int max2(int a, int b) {
    return ((a > b)? a : b);
}

inline int max3(int a, int b, int c) {
    return max2(a, max2(b, c));
}

/*Solution code starts here */
   
#define maxn 300009
#define maxt 2060009

long long int Array[maxn];
int n;
     

class node
{
      public:
             
   int st,ed;
   long long add,sum;
   
   node()
    {add=0,sum=0;
    }
        
   node(int l , int r)
   { st=l;
     ed=r;
     add=0;sum=0;
    } 
   
   
  
    void merge(node L,node R)
    { 
     if( L.st==-1)
        sum=R.sum+R.add*(R.ed-R.st+1);        
     else if( R.st==-1)
        sum= L.sum + L.add*(L.ed-L.st+1);  
     else
        sum= L.sum + L.add*(L.ed-L.st+1) + R.sum + R.add*(R.ed-R.st+1);  
              
    } 
    
    void split( node& L ,  node& R )
     {
        sum+=add*(ed-st+1);
        
        if(ed!=st)
        { L.add+=add;
          R.add+=add;
        }      
        
         add=0;
    }//end spilt    
 
   
};    
   
node ident;
node Tree[maxt];
  
class SegmentTree
{
      public:
          
    
          
      
            void build(int  no ,int  l , int   r)
             {
                 
               if(r==l)
                { Tree[no].st=Tree[no].ed=r;
                  Tree[no].sum=Array[r];
                  Tree[no].add=0;               
                  return ;
                }
                
                int  lc=2*no;
                int  rc=2*no+1;
                
                int  mid=(l+r)/2;

                build(lc,l,mid);
                build(rc,mid+1,r); 
                
                Tree[no]=node(l,r);               
               
                Tree[no].merge( Tree[lc] , Tree[rc] );                
               
             }  
             
             
 node  query(int   no, int l,int r, int  i, int j)
    {
      int  lc=2*no;
      int rc=2*no+1;
      int mid=(l+r)/2;

      if( l >= i && r<=j )// 
        {
          if( Tree[no].add > 0 )
            Tree[no].split( Tree[lc],Tree[rc] );
            
            return Tree[no];
        }  
        
        if( j < l || i > r)
          return ident;
          
          
        if( Tree[no].add >0 )
          Tree[no].split( Tree[lc]  , Tree[rc] );
          
        node a=query(lc,l,    mid,i,j);
        node b=query(rc,mid+1, r, i,j);
        
         node ans;
         ans.merge(a,b);
         return ans;    
    
    } 
    
    void update(int  no ,int l , int r , int i , int j ,int val)
     {
        if( i <=l && j >=r )
         { Tree[no].add+=val;
           Tree[no].split( Tree[2*no],Tree[2*no+1] );
           return ;
         }
         
         if( j < l || i >r )
           return ;
           
          int mid=(l+r)/2;
           
          update(2*no , l,    mid ,i,j,val);
          update(2*no+1,mid+1 ,r  ,i,j,val);
          
          Tree[no].merge( Tree[2*no] , Tree[2*no+1] );       
            
      }                      
                       
             
};


int main()
{
 ident=node(-1,-1);   


int q;
    
 cin>>n>>q;
 
 
 vector<long long > in;
 long long x,y;
 
 for(int i=0;i<n;i++)
  { cin>>x;
    in.pb(x);
   }   
    
 memset(Array,0 ,sizeof(Array) );
     
 SegmentTree st;
     
  st.build(1,0,n-1);
     

     for(int k=1;k<=q;k++)
      {   
         cin>>x>>y;           
        st.update(1,0,n-1,x-1,y-1,1);        
      }  
      
     
  /*  else if(op==1)
            { scanf("%d%d",&x,&y);
              printf("%lld\n",(st.query(1,0,n-1,x-1,y-1) ).sum ); 
             }  
      */
      
      vector<long long > cont;
      
      for(int i=0;i<n;i++)
        {  x=(st.query(1,0,n-1,i,i) ).sum;   
          cont.pb(x);
        } 
        
        
        sort( cont.begin() , cont.end() );
        sort( in.begin() , in.end() );
        
        long long ans=0;
        
        for(int i=0;i<n;i++)
           { //cout<<in[i]<<"  "<<cont[i]<<endl;
          ans=ans+(long long)( in[i]*cont[i] );
          } 
          
          cout<<ans<<endl;        
     
     return 0;
}     
     
               
     
