from bisect import bisect_left

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

change=[tuple(map(int,input().split())) for _ in range(M)]
change=sorted(change,key=lambda x: x[1],reverse=True)
change2=[]
count=0
for i in range(M):
  b,c=change[i]
  change2.extend([c]*b)
  count += b
  if count >= N:break

A.extend(change2)
A = sorted(A)
print(sum(A[len(A)-N:])) from bisect import bisect_left 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 A=sorted(A) A sorted(A) sorted A tuple(map(int,input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split change=[tuple(map(int,input().split())) for _ in range(M)] change [tuple(map(int,input().split())) for _ in range(M)] change=sorted(change,key=lambda x: x[1],reverse=True) change sorted(change,key=lambda x: x[1],reverse=True) sorted change key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True change2=[] change2 [] count=0 count 0 for i in range(M):
  b,c=change[i]
  change2.extend([c]*b)
  count += b
  if count >= N:break i range(M) range M b,c=change[i] b change[i] change i c change2.extend([c]*b) change2.extend change2 extend [c]*b [c] c b count += b count b if count >= N:bre count >= N count N A.extend(change2) A.extend A extend change2 A = sorted(A) A sorted(A) sorted A print(sum(A[len(A)-N:])) print sum(A[len(A)-N:]) sum A[len(A)-N:] A len(A)-N: len(A)-N len(A) len A N A = sorted(A) sorted(A) A N,M=map(int,input().split()) map(int,input().split()) N change=sorted(change,key=lambda x: x[1],reverse=True) sorted(change,key=lambda x: x[1],reverse=True) change change=[tuple(map(int,input().split())) for _ in range(M)] [tuple(map(int,input().split())) for _ in range(M)] change change2=[] [] change2 c=change[i] change[i] c A=sorted(A) sorted(A) A A=list(map(int,input().split())) list(map(int,input().split())) A count += b b count count=0 0 count b,c=change[i] change[i] b M=map(int,input().split()) map(int,input().split()) M
from bisect import bisect_left

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

change=[tuple(map(int,input().split())) for _ in range(M)]
change=sorted(change,key=lambda x: x[1],reverse=True)
change2=[]
count=0
for i in range(M):
  b,c=change[i]
  change2.extend([c]*b)
  count += b
  if count >= N:break

A.extend(change2)
A = sorted(A)
print(sum(A[len(A)-N:]))