
import sys
from bisect import bisect_left,bisect,bisect_right

icase=0
if icase==0:
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    d=[]
    cb=[[0]*2 for i in range(m)]
    for i in range(m):
        bi,ci=map(int,input().split())
        cb[i]=[ci,bi]
elif icase==2:
    n,m=10,3
    a=[1, 4, 5, 5, 7, 8, 13, 33, 52, 100]
    cb=[[30, 4], [10, 3], [4, 1]]

a.sort()
cb.sort(reverse=True)
    
asum=0
isum=0
isumm=0
for i in range(m):
    isum+=cb[i][1]
    if isum>n:
        if a[n-1]<=cb[i][0]:
            asum+=cb[i][0]*(n-isumm)
            print(asum)
            sys.exit()
        else:
            ii=bisect_right(a,cb[i][0])
            asum+=cb[i][0]*(ii-isumm)
            asum+=sum(a[ii:])
            print(asum)
            sys.exit()
    if a[isum-1]<=cb[i][0]:
        asum+=cb[i][0]*cb[i][1]
        isumm=isum
        continue
    else:
        ii=bisect_right(a,cb[i][0])
        asum+=cb[i][0]*(ii-isumm)
        asum+=sum(a[ii:])
        print(asum)
        sys.exit()
    
asum+=sum(a[isum:])
        
print(asum) import sys sys from bisect import bisect_left,bisect,bisect_right icase=0 icase 0 if icase==0:
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    d=[]
    cb=[[0]*2 for i in range(m)]
    for i in range(m):
        bi,ci=map(int,input().split())
        cb[i]=[ci,bi]
elif icase==2:
    n,m=10,3
    a=[1, 4, 5, 5, 7, 8, 13, 33, 52, 100]
    cb=[[30, 4], [10, 3], [4, 1]] icase==0 icase 0 n,m=map(int,input().split()) n 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 d=[] d [] [0]*2 for i in range(m) for i in range(m) i range(m) range m for i in range(m) [0]*2 [0] 0 2 cb=[[0]*2 for i in range(m)] cb [[0]*2 for i in range(m)] for i in range(m):
        bi,ci=map(int,input().split())
        cb[i]=[ci,bi] i range(m) range m bi,ci=map(int,input().split()) bi map(int,input().split()) map int input().split() ().split () input split ci cb[i]=[ci,bi] cb[i] cb i [ci,bi] ci bi elif icase==2:
    n,m=10,3
    a=[1, 4, 5, 5, 7, 8, 13, 33, 52, 100]
    cb=[[30, 4], [10, 3], [4, 1]] icase==2 icase 2 n,m=10,3 n 10 m 3 a=[1, 4, 5, 5, 7, 8, 13, 33, 52, 100] a [1, 4, 5, 5, 7, 8, 13, 33, 52, 100] 1 4 5 5 7 8 13 33 52 100 cb=[[30, 4], [10, 3], [4, 1]] cb [[30, 4], [10, 3], [4, 1]] [30, 4] 30 4 [10, 3] 10 3 [4, 1] 4 1 a.sort() a.sort a sort cb.sort(reverse=True) cb.sort cb sort reverse=True reverse True asum=0 asum 0 isum=0 isum 0 isumm=0 isumm 0 for i in range(m):
    isum+=cb[i][1]
    if isum>n:
        if a[n-1]<=cb[i][0]:
            asum+=cb[i][0]*(n-isumm)
            print(asum)
            sys.exit()
        else:
            ii=bisect_right(a,cb[i][0])
            asum+=cb[i][0]*(ii-isumm)
            asum+=sum(a[ii:])
            print(asum)
            sys.exit()
    if a[isum-1]<=cb[i][0]:
        asum+=cb[i][0]*cb[i][1]
        isumm=isum
        continue
    else:
        ii=bisect_right(a,cb[i][0])
        asum+=cb[i][0]*(ii-isumm)
        asum+=sum(a[ii:])
        print(asum)
        sys.exit()
     i range(m) range m isum+=cb[i][1] isum cb[i][1] [i] cb i 1 if isum>n:
        if a[n-1]<=cb[i][0]:
            asum+=cb[i][0]*(n-isumm)
            print(asum)
            sys.exit()
        else:
            ii=bisect_right(a,cb[i][0])
            asum+=cb[i][0]*(ii-isumm)
            asum+=sum(a[ii:])
            print(asum)
            sys.exit()
     isum>n isum n if a[n-1]<=cb[i][0]:
            asum+=cb[i][0]*(n-isumm)
            print(asum)
            sys.exit()
        else:
            ii=bisect_right(a,cb[i][0])
            asum+=cb[i][0]*(ii-isumm)
            asum+=sum(a[ii:])
            print(asum)
            sys.exit()
     a[n-1]<=cb[i][0] a[n-1] a n-1 n 1 cb[i][0] [i] cb i 0 asum+=cb[i][0]*(n-isumm) asum cb[i][0]*(n-isumm) cb[i][0] [i] cb i 0 n-isumm n isumm print(asum) print asum sys.exit() sys.exit sys exit ii=bisect_right(a,cb[i][0]) ii bisect_right(a,cb[i][0]) bisect_right a cb[i][0] [i] cb i 0 asum+=cb[i][0]*(ii-isumm) asum cb[i][0]*(ii-isumm) cb[i][0] [i] cb i 0 ii-isumm ii isumm asum+=sum(a[ii:]) asum sum(a[ii:]) sum a[ii:] a ii: ii print(asum) print asum sys.exit() sys.exit sys exit if a[isum-1]<=cb[i][0]:
        asum+=cb[i][0]*cb[i][1]
        isumm=isum
        continue
    else:
        ii=bisect_right(a,cb[i][0])
        asum+=cb[i][0]*(ii-isumm)
        asum+=sum(a[ii:])
        print(asum)
        sys.exit()
     a[isum-1]<=cb[i][0] a[isum-1] a isum-1 isum 1 cb[i][0] [i] cb i 0 asum+=cb[i][0]*cb[i][1] asum cb[i][0]*cb[i][1] cb[i][0] [i] cb i 0 cb[i][1] [i] cb i 1 isumm=isum isumm isum continue ii=bisect_right(a,cb[i][0]) ii bisect_right(a,cb[i][0]) bisect_right a cb[i][0] [i] cb i 0 asum+=cb[i][0]*(ii-isumm) asum cb[i][0]*(ii-isumm) cb[i][0] [i] cb i 0 ii-isumm ii isumm asum+=sum(a[ii:]) asum sum(a[ii:]) sum a[ii:] a ii: ii print(asum) print asum sys.exit() sys.exit sys exit asum+=sum(a[isum:]) asum sum(a[isum:]) sum a[isum:] a isum: isum print(asum) print asum cb=[[30, 4], [10, 3], [4, 1]] [[30, 4], [10, 3], [4, 1]] cb asum+=cb[i][0]*(n-isumm) cb[i][0]*(n-isumm) asum asum+=sum(a[ii:]) sum(a[ii:]) asum isumm=isum isum isumm asum+=cb[i][0]*(ii-isumm) cb[i][0]*(ii-isumm) asum cb=[[0]*2 for i in range(m)] [[0]*2 for i in range(m)] cb n,m=10,3 10 n bi,ci=map(int,input().split()) map(int,input().split()) bi a=list(map(int,input().split())) list(map(int,input().split())) a d=[] [] d asum+=cb[i][0]*(ii-isumm) cb[i][0]*(ii-isumm) asum ii=bisect_right(a,cb[i][0]) bisect_right(a,cb[i][0]) ii ii=bisect_right(a,cb[i][0]) bisect_right(a,cb[i][0]) ii a=[1, 4, 5, 5, 7, 8, 13, 33, 52, 100] [1, 4, 5, 5, 7, 8, 13, 33, 52, 100] a asum=0 0 asum asum+=cb[i][0]*cb[i][1] cb[i][0]*cb[i][1] asum asum+=sum(a[ii:]) sum(a[ii:]) asum m=map(int,input().split()) map(int,input().split()) m ci=map(int,input().split()) map(int,input().split()) ci m=10,3 3 m asum+=sum(a[isum:]) sum(a[isum:]) asum isumm=0 0 isumm icase=0 0 icase isum=0 0 isum n,m=map(int,input().split()) map(int,input().split()) n isum+=cb[i][1] cb[i][1] isum

import sys
from bisect import bisect_left,bisect,bisect_right

icase=0
if icase==0:
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    d=[]
    cb=[[0]*2 for i in range(m)]
    for i in range(m):
        bi,ci=map(int,input().split())
        cb[i]=[ci,bi]
elif icase==2:
    n,m=10,3
    a=[1, 4, 5, 5, 7, 8, 13, 33, 52, 100]
    cb=[[30, 4], [10, 3], [4, 1]]

a.sort()
cb.sort(reverse=True)
    
asum=0
isum=0
isumm=0
for i in range(m):
    isum+=cb[i][1]
    if isum>n:
        if a[n-1]<=cb[i][0]:
            asum+=cb[i][0]*(n-isumm)
            print(asum)
            sys.exit()
        else:
            ii=bisect_right(a,cb[i][0])
            asum+=cb[i][0]*(ii-isumm)
            asum+=sum(a[ii:])
            print(asum)
            sys.exit()
    if a[isum-1]<=cb[i][0]:
        asum+=cb[i][0]*cb[i][1]
        isumm=isum
        continue
    else:
        ii=bisect_right(a,cb[i][0])
        asum+=cb[i][0]*(ii-isumm)
        asum+=sum(a[ii:])
        print(asum)
        sys.exit()
    
asum+=sum(a[isum:])
        
print(asum)
