N,M=map(int,input().split())
arr=[int(x) for x in input().split()]
s=[list(map(int,input().split())) for y in range(M)]
s.sort(key=lambda z: z[1], reverse=True)

sum_a=0
for a,b in s:
    arr+=[b]*a
    sum_a+=a
    if sum_a>=N:
        break

lst=sorted(arr)
ans=sum(lst[-N:])
print(ans) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x arr=[int(x) for x in input().split()] arr [int(x) for x in input().split()] list(map(int,input().split())) for y in range(M) for y in range(M) y range(M) range M for y in range(M) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split s=[list(map(int,input().split())) for y in range(M)] s [list(map(int,input().split())) for y in range(M)] s.sort(key=lambda z: z[1], reverse=True) s.sort s sort key=lambda z: z[1] key lambda z: z[1] z[1] z 1 z reverse=True reverse True sum_a=0 sum_a 0 for a,b in s:
    arr+=[b]*a
    sum_a+=a
    if sum_a>=N:
        break a b s arr+=[b]*a arr [b]*a [b] b a sum_a+=a sum_a a if sum_a>=N:
        break sum_a>=N sum_a N break lst=sorted(arr) lst sorted(arr) sorted arr ans=sum(lst[-N:]) ans sum(lst[-N:]) sum lst[-N:] lst -N: -N N print(ans) print ans N,M=map(int,input().split()) map(int,input().split()) N lst=sorted(arr) sorted(arr) lst M=map(int,input().split()) map(int,input().split()) M arr=[int(x) for x in input().split()] [int(x) for x in input().split()] arr arr+=[b]*a [b]*a arr s=[list(map(int,input().split())) for y in range(M)] [list(map(int,input().split())) for y in range(M)] s ans=sum(lst[-N:]) sum(lst[-N:]) ans sum_a=0 0 sum_a sum_a+=a a sum_a
N,M=map(int,input().split())
arr=[int(x) for x in input().split()]
s=[list(map(int,input().split())) for y in range(M)]
s.sort(key=lambda z: z[1], reverse=True)

sum_a=0
for a,b in s:
    arr+=[b]*a
    sum_a+=a
    if sum_a>=N:
        break

lst=sorted(arr)
ans=sum(lst[-N:])
print(ans)