N,M = map(int,input().split())
Ali = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

Ali.sort()
BC.sort(key=lambda x:x[1],reverse=True)
i = 0
j = 0

while i<N and j<M:
  if Ali[i]>=BC[j][1]:
    break
  Ali[i] = BC[j][1]
  i += 1
  BC[j][0] -= 1
  if BC[j][0] == 0:
    j += 1

print(sum(Ali)) N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M Ali = list(map(int,input().split())) Ali list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split list(map(int,input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split BC = [list(map(int,input().split())) for _ in range(M)] BC [list(map(int,input().split())) for _ in range(M)] Ali.sort() Ali.sort Ali sort BC.sort(key=lambda x:x[1],reverse=True) BC.sort BC sort key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse=True reverse True i = 0 i 0 j = 0 j 0 while i<N and j<M:
  if Ali[i]>=BC[j][1]:
    break
  Ali[i] = BC[j][1]
  i += 1
  BC[j][0] -= 1
  if BC[j][0] == 0:
    j += 1 i<N and j<M i<N i N j<M j M if Ali[i]>=BC[j][1]:
    break
   Ali[i]>=BC[j][1] Ali[i] Ali i BC[j][1] [j] BC j 1 break Ali[i] = BC[j][1] Ali[i] Ali i BC[j][1] [j] BC j 1 i += 1 i 1 BC[j][0] -= 1 BC[j][0] [j] BC j 0 1 if BC[j][0] == 0:
    j += 1 BC[j][0] == 0 BC[j][0] [j] BC j 0 0 j += 1 j 1 print(sum(Ali)) print sum(Ali) sum Ali j += 1 1 j BC = [list(map(int,input().split())) for _ in range(M)] [list(map(int,input().split())) for _ in range(M)] BC M = map(int,input().split()) map(int,input().split()) M j = 0 0 j N,M = map(int,input().split()) map(int,input().split()) N i = 0 0 i Ali = list(map(int,input().split())) list(map(int,input().split())) Ali i += 1 1 i
N,M = map(int,input().split())
Ali = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

Ali.sort()
BC.sort(key=lambda x:x[1],reverse=True)
i = 0
j = 0

while i<N and j<M:
  if Ali[i]>=BC[j][1]:
    break
  Ali[i] = BC[j][1]
  i += 1
  BC[j][0] -= 1
  if BC[j][0] == 0:
    j += 1

print(sum(Ali))