N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
CB=[]
for i in range(M):
  B,C=map(int,input().split())
  CB.append([C,B])
CB.sort(reverse=True)

idx=0
for C,B in CB:
  for i in range(B):
    if not idx>=len(A) and A[idx]<C:
      A[idx]=C
      idx+=1
    else:
      break
print(sum(A)) 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.sort() A.sort A sort CB=[] CB [] for i in range(M):
  B,C=map(int,input().split())
  CB.append([C,B]) i range(M) range M B,C=map(int,input().split()) B map(int,input().split()) map int input().split() ().split () input split C CB.append([C,B]) CB.append CB append [C,B] C B CB.sort(reverse=True) CB.sort CB sort reverse=True reverse True idx=0 idx 0 for C,B in CB:
  for i in range(B):
    if not idx>=len(A) and A[idx]<C:
      A[idx]=C
      idx+=1
    else:
      break C B CB for i in range(B):
    if not idx>=len(A) and A[idx]<C:
      A[idx]=C
      idx+=1
    else:
      break i range(B) range B if not idx>=len(A) and A[idx]<C:
      A[idx]=C
      idx+=1
    else:
      break not idx>=len(A) and A[idx]<C not idx>=len(A) idx>=len(A) idx len(A) len A A[idx]<C A[idx] A idx C A[idx]=C A[idx] A idx C idx+=1 idx 1 break print(sum(A)) print sum(A) sum A A=list(map(int,input().split())) list(map(int,input().split())) A N,M=map(int,input().split()) map(int,input().split()) N M=map(int,input().split()) map(int,input().split()) M idx+=1 1 idx C=map(int,input().split()) map(int,input().split()) C idx=0 0 idx CB=[] [] CB B,C=map(int,input().split()) map(int,input().split()) B
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
CB=[]
for i in range(M):
  B,C=map(int,input().split())
  CB.append([C,B])
CB.sort(reverse=True)

idx=0
for C,B in CB:
  for i in range(B):
    if not idx>=len(A) and A[idx]<C:
      A[idx]=C
      idx+=1
    else:
      break
print(sum(A))
