from bisect import bisect_left, bisect_right

def readinput():
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=[]
    c=[]
    for _ in range(m):
        bb,cc=list(map(int,input().split()))
        b.append(bb)
        c.append(cc)
    return n,m,a,b,c

def main(n,m,a,b,c):
    a.sort()
    for i in range(m):
        #print(a)
        bi=b[i]
        ci=c[i]
        j=bisect_left(a,ci)-1
        if j<0:
            continue
        if j>bi-1:
            save=a[bi:j+1]
            l=j-bi+1
            r=j
            a[l:r+1]=[ci]*(r-l+1)
            a[0:l]=save
        else:
            l=0
            r=j
            a[l:r+1]=[ci]*(r-l+1)

    sum=0
    for i in range(n):
        sum+=a[i]
    
    return sum

def main2(n,m,a,b,c):
    all=[]
    for i in range(n):
        all.append((a[i],1))
    for i in range(m):
        all.append((c[i],b[i]))
    all.sort(reverse=True, key=lambda x:x[0])
    #print(all)
    count=n
    sum=0
    i=0
    while(count>0):
        ni=all[i][1]
        if ni<=count:
            sum+=all[i][0]*ni
            count-=ni
        else:
            sum+=all[i][0]*count
            count=0
        i+=1
        #print(sum,count)
    return sum

if __name__=='__main__':
    n,m,a,b,c=readinput()
    ans=main2(n,m,a,b,c)
    print(ans) from bisect import bisect_left, bisect_right def readinput():
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=[]
    c=[]
    for _ in range(m):
        bb,cc=list(map(int,input().split()))
        b.append(bb)
        c.append(cc)
    return n,m,a,b,c readinput n,m=list(map(int,input().split())) n list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split m a=list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split b=[] b [] c=[] c [] for _ in range(m):
        bb,cc=list(map(int,input().split()))
        b.append(bb)
        c.append(cc)
     _ range(m) range m bb,cc=list(map(int,input().split())) bb list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split cc b.append(bb) b.append b append bb c.append(cc) c.append c append cc return n,m,a,b,c return n,m,a,b,c n m a b c def main(n,m,a,b,c):
    a.sort()
    for i in range(m):
        #print(a)
        bi=b[i]
        ci=c[i]
        j=bisect_left(a,ci)-1
        if j<0:
            continue
        if j>bi-1:
            save=a[bi:j+1]
            l=j-bi+1
            r=j
            a[l:r+1]=[ci]*(r-l+1)
            a[0:l]=save
        else:
            l=0
            r=j
            a[l:r+1]=[ci]*(r-l+1)

    sum=0
    for i in range(n):
        sum+=a[i]
    
    return sum main a.sort() a.sort a sort for i in range(m):
        #print(a)
        bi=b[i]
        ci=c[i]
        j=bisect_left(a,ci)-1
        if j<0:
            continue
        if j>bi-1:
            save=a[bi:j+1]
            l=j-bi+1
            r=j
            a[l:r+1]=[ci]*(r-l+1)
            a[0:l]=save
        else:
            l=0
            r=j
            a[l:r+1]=[ci]*(r-l+1)

     i range(m) range m bi=b[i] bi b[i] b i ci=c[i] ci c[i] c i j=bisect_left(a,ci)-1 j bisect_left(a,ci)-1 bisect_left(a,ci) bisect_left a ci 1 if j<0:
            continue
         j<0 j 0 continue if j>bi-1:
            save=a[bi:j+1]
            l=j-bi+1
            r=j
            a[l:r+1]=[ci]*(r-l+1)
            a[0:l]=save
        else:
            l=0
            r=j
            a[l:r+1]=[ci]*(r-l+1)

     j>bi-1 j bi-1 bi 1 save=a[bi:j+1] save a[bi:j+1] a bi:j+1 bi j+1 j 1 l=j-bi+1 l j-bi+1 j-bi j bi 1 r=j r j a[l:r+1]=[ci]*(r-l+1) a[l:r+1] a l:r+1 l r+1 r 1 [ci]*(r-l+1) [ci] ci r-l+1 r-l r l 1 a[0:l]=save a[0:l] a 0:l 0 l save l=0 l 0 r=j r j a[l:r+1]=[ci]*(r-l+1) a[l:r+1] a l:r+1 l r+1 r 1 [ci]*(r-l+1) [ci] ci r-l+1 r-l r l 1 sum=0 sum 0 for i in range(n):
        sum+=a[i]
    
     i range(n) range n sum+=a[i] sum a[i] a i return sum sum n n m m a a b b c c def main2(n,m,a,b,c):
    all=[]
    for i in range(n):
        all.append((a[i],1))
    for i in range(m):
        all.append((c[i],b[i]))
    all.sort(reverse=True, key=lambda x:x[0])
    #print(all)
    count=n
    sum=0
    i=0
    while(count>0):
        ni=all[i][1]
        if ni<=count:
            sum+=all[i][0]*ni
            count-=ni
        else:
            sum+=all[i][0]*count
            count=0
        i+=1
        #print(sum,count)
    return sum main2 all=[] all [] for i in range(n):
        all.append((a[i],1))
     i range(n) range n all.append((a[i],1)) all.append all append (a[i],1) a[i] a i 1 for i in range(m):
        all.append((c[i],b[i]))
     i range(m) range m all.append((c[i],b[i])) all.append all append (c[i],b[i]) c[i] c i b[i] b i all.sort(reverse=True, key=lambda x:x[0]) all.sort all sort reverse=True reverse True key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x count=n count n sum=0 sum 0 i=0 i 0 while(count>0):
        ni=all[i][1]
        if ni<=count:
            sum+=all[i][0]*ni
            count-=ni
        else:
            sum+=all[i][0]*count
            count=0
        i+=1
        #print(sum,count)
     count>0 count 0 ni=all[i][1] ni all[i][1] [i] all i 1 if ni<=count:
            sum+=all[i][0]*ni
            count-=ni
        else:
            sum+=all[i][0]*count
            count=0
         ni<=count ni count sum+=all[i][0]*ni sum all[i][0]*ni all[i][0] [i] all i 0 ni count-=ni count ni sum+=all[i][0]*count sum all[i][0]*count all[i][0] [i] all i 0 count count=0 count 0 i+=1 i 1 return sum sum n n m m a a b b c c if __name__=='__main__':
    n,m,a,b,c=readinput()
    ans=main2(n,m,a,b,c)
    print(ans) __name__=='__main__' __name__ '__main__' n,m,a,b,c=readinput() n readinput() readinput m a b c ans=main2(n,m,a,b,c) ans main2(n,m,a,b,c) main2 n m a b c print(ans) print ans def main2(n,m,a,b,c):
    all=[]
    for i in range(n):
        all.append((a[i],1))
    for i in range(m):
        all.append((c[i],b[i]))
    all.sort(reverse=True, key=lambda x:x[0])
    #print(all)
    count=n
    sum=0
    i=0
    while(count>0):
        ni=all[i][1]
        if ni<=count:
            sum+=all[i][0]*ni
            count-=ni
        else:
            sum+=all[i][0]*count
            count=0
        i+=1
        #print(sum,count)
    return sum def main2(n,m,a,b,c):
    all=[]
    for i in range(n):
        all.append((a[i],1))
    for i in range(m):
        all.append((c[i],b[i]))
    all.sort(reverse=True, key=lambda x:x[0])
    #print(all)
    count=n
    sum=0
    i=0
    while(count>0):
        ni=all[i][1]
        if ni<=count:
            sum+=all[i][0]*ni
            count-=ni
        else:
            sum+=all[i][0]*count
            count=0
        i+=1
        #print(sum,count)
    return sum main2 n,m,a,b,c=readinput() readinput() n ans=main2(n,m,a,b,c) main2(n,m,a,b,c) ans b,c=readinput() readinput() b c=readinput() readinput() c def main(n,m,a,b,c):
    a.sort()
    for i in range(m):
        #print(a)
        bi=b[i]
        ci=c[i]
        j=bisect_left(a,ci)-1
        if j<0:
            continue
        if j>bi-1:
            save=a[bi:j+1]
            l=j-bi+1
            r=j
            a[l:r+1]=[ci]*(r-l+1)
            a[0:l]=save
        else:
            l=0
            r=j
            a[l:r+1]=[ci]*(r-l+1)

    sum=0
    for i in range(n):
        sum+=a[i]
    
    return sum def main(n,m,a,b,c):
    a.sort()
    for i in range(m):
        #print(a)
        bi=b[i]
        ci=c[i]
        j=bisect_left(a,ci)-1
        if j<0:
            continue
        if j>bi-1:
            save=a[bi:j+1]
            l=j-bi+1
            r=j
            a[l:r+1]=[ci]*(r-l+1)
            a[0:l]=save
        else:
            l=0
            r=j
            a[l:r+1]=[ci]*(r-l+1)

    sum=0
    for i in range(n):
        sum+=a[i]
    
    return sum main def readinput():
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=[]
    c=[]
    for _ in range(m):
        bb,cc=list(map(int,input().split()))
        b.append(bb)
        c.append(cc)
    return n,m,a,b,c def readinput():
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=[]
    c=[]
    for _ in range(m):
        bb,cc=list(map(int,input().split()))
        b.append(bb)
        c.append(cc)
    return n,m,a,b,c readinput m,a,b,c=readinput() readinput() m a,b,c=readinput() readinput() a
from bisect import bisect_left, bisect_right

def readinput():
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=[]
    c=[]
    for _ in range(m):
        bb,cc=list(map(int,input().split()))
        b.append(bb)
        c.append(cc)
    return n,m,a,b,c

def main(n,m,a,b,c):
    a.sort()
    for i in range(m):
        #print(a)
        bi=b[i]
        ci=c[i]
        j=bisect_left(a,ci)-1
        if j<0:
            continue
        if j>bi-1:
            save=a[bi:j+1]
            l=j-bi+1
            r=j
            a[l:r+1]=[ci]*(r-l+1)
            a[0:l]=save
        else:
            l=0
            r=j
            a[l:r+1]=[ci]*(r-l+1)

    sum=0
    for i in range(n):
        sum+=a[i]
    
    return sum

def main2(n,m,a,b,c):
    all=[]
    for i in range(n):
        all.append((a[i],1))
    for i in range(m):
        all.append((c[i],b[i]))
    all.sort(reverse=True, key=lambda x:x[0])
    #print(all)
    count=n
    sum=0
    i=0
    while(count>0):
        ni=all[i][1]
        if ni<=count:
            sum+=all[i][0]*ni
            count-=ni
        else:
            sum+=all[i][0]*count
            count=0
        i+=1
        #print(sum,count)
    return sum

if __name__=='__main__':
    n,m,a,b,c=readinput()
    ans=main2(n,m,a,b,c)
    print(ans)
