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.
import math
import copy
import itertools
import bisect
import sys

input = sys.stdin.readline

def ilst():
    return list(map(int,input().split()))
    
def islst():
    return list(map(str,input().split()))
    
def inum():
    return map(int,input().split())
    
def freq(l):
    d = {}
    for i in l:
        d[i] = d.get(i,0)+1
    return d
    
def issub(s1,s2):   #s2 is a sub of s1
    j = 0
    for i in range(len(s1)):
        if s1[i] == s2[j]:
            j += 1
        if j == len(s2):
            return True
    return False

def prime_eratosthenes(n):
    prime_list = []
    l = []
    for i in range(2, n+1):
        if i not in prime_list:
            l.append(i)
            for j in range(i*i, n+1, i):
                prime_list.append(j)
    return l
            
def isPrime(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True


n,k = inum()
l = ilst()

qlst = []
for i in range(k):
    qlst.append(ilst())
    
d = {}

for i in qlst:
    for j in range(i[0]-1,i[1]):
        d[j] = d.get(j,0) + 1

nl = []

for i in d:
    nl.append([d[i],i])
    
nl.sort(reverse = True)
l.sort(reverse = True)

for i in range(n):
    nl[i] += [l[i]]
    
nl = sorted(nl, key = lambda x:x[1])

pref = [0]*(n+1)

for i in range(n):
    pref[i+1] = pref[i] + nl[i][2]
    

ans = 0
for i in range(len(qlst)):
    ans += pref[qlst[i][1]]-pref[qlst[i][0]-1]
print(ans)