import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))

D={}
for _ in range(M):
    B,C=map(int,input().split())
    if -C in D:
        D[-C]+=B
    else:
        D[-C]=B

H=list(D.items())
heapq.heapify(H)

G=[]
Y=0
while Y<N and H:
    (a,k)=heapq.heappop(H)
    a=-a
    k=min(k,N-Y)
    A+=[a]*k
    Y+=k

A.sort(reverse=True)
print(sum(A[:N])) import heapq heapq 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 {} for _ in range(M):
    B,C=map(int,input().split())
    if -C in D:
        D[-C]+=B
    else:
        D[-C]=B _ range(M) range M B,C=map(int,input().split()) B map(int,input().split()) map int input().split() ().split () input split C if -C in D:
        D[-C]+=B
    else:
        D[-C]=B -C in D -C C D D[-C]+=B D[-C] D -C C B D[-C]=B D[-C] D -C C B H=list(D.items()) H list(D.items()) list D.items() D.items D items heapq.heapify(H) heapq.heapify heapq heapify H G=[] G [] Y=0 Y 0 while Y<N and H:
    (a,k)=heapq.heappop(H)
    a=-a
    k=min(k,N-Y)
    A+=[a]*k
    Y+=k Y<N and H Y<N Y N H (a,k)=heapq.heappop(H) (a,k) a k heapq.heappop(H) heapq.heappop heapq heappop H a=-a a -a a k=min(k,N-Y) k min(k,N-Y) min k N-Y N Y A+=[a]*k A [a]*k [a] a k Y+=k Y k A.sort(reverse=True) A.sort A sort reverse=True reverse True print(sum(A[:N])) print sum(A[:N]) sum A[:N] A :N N M=map(int,input().split()) map(int,input().split()) M C=map(int,input().split()) map(int,input().split()) C Y=0 0 Y a=-a -a a N,M=map(int,input().split()) map(int,input().split()) N G=[] [] G Y+=k k Y k=min(k,N-Y) min(k,N-Y) k B,C=map(int,input().split()) map(int,input().split()) B D={} {} D A=list(map(int,input().split())) list(map(int,input().split())) A A+=[a]*k [a]*k A H=list(D.items()) list(D.items()) H
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))

D={}
for _ in range(M):
    B,C=map(int,input().split())
    if -C in D:
        D[-C]+=B
    else:
        D[-C]=B

H=list(D.items())
heapq.heapify(H)

G=[]
Y=0
while Y<N and H:
    (a,k)=heapq.heappop(H)
    a=-a
    k=min(k,N-Y)
    A+=[a]*k
    Y+=k

A.sort(reverse=True)
print(sum(A[:N]))