n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
BC=[list(map(int,input().split())) for i in range(m)]
BC=sorted(BC,reverse=True,key=lambda x: x[1])
flag=0
t=0
for i in range(m):
  if flag==1:
    break
  for j in range(t,n):
    if BC[i][1]>A[j]:
      A[j]=BC[i][1]
      BC[i][0]-=1
      t=j+1
      if BC[i][0]==0:
        break
    else:
      flag=1
      break
print(sum(A)) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m A=sorted(list(map(int,input().split()))) A sorted(list(map(int,input().split()))) sorted list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split list(map(int,input().split())) for i in range(m) for i in range(m) i range(m) range m for i 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 i in range(m)] BC [list(map(int,input().split())) for i in range(m)] BC=sorted(BC,reverse=True,key=lambda x: x[1]) BC sorted(BC,reverse=True,key=lambda x: x[1]) sorted BC reverse=True reverse True key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x flag=0 flag 0 t=0 t 0 for i in range(m):
  if flag==1:
    break
  for j in range(t,n):
    if BC[i][1]>A[j]:
      A[j]=BC[i][1]
      BC[i][0]-=1
      t=j+1
      if BC[i][0]==0:
        break
    else:
      flag=1
      break i range(m) range m if flag==1:
    break
   flag==1 flag 1 break for j in range(t,n):
    if BC[i][1]>A[j]:
      A[j]=BC[i][1]
      BC[i][0]-=1
      t=j+1
      if BC[i][0]==0:
        break
    else:
      flag=1
      break j range(t,n) range t n if BC[i][1]>A[j]:
      A[j]=BC[i][1]
      BC[i][0]-=1
      t=j+1
      if BC[i][0]==0:
        break
    else:
      flag=1
      break BC[i][1]>A[j] BC[i][1] [i] BC i 1 A[j] A j A[j]=BC[i][1] A[j] A j BC[i][1] [i] BC i 1 BC[i][0]-=1 BC[i][0] [i] BC i 0 1 t=j+1 t j+1 j 1 if BC[i][0]==0:
        break
     BC[i][0]==0 BC[i][0] [i] BC i 0 0 break flag=1 flag 1 break print(sum(A)) print sum(A) sum A t=0 0 t BC=[list(map(int,input().split())) for i in range(m)] [list(map(int,input().split())) for i in range(m)] BC n,m=map(int,input().split()) map(int,input().split()) n BC=sorted(BC,reverse=True,key=lambda x: x[1]) sorted(BC,reverse=True,key=lambda x: x[1]) BC m=map(int,input().split()) map(int,input().split()) m A=sorted(list(map(int,input().split()))) sorted(list(map(int,input().split()))) A flag=0 0 flag t=j+1 j+1 t flag=1 1 flag
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
BC=[list(map(int,input().split())) for i in range(m)]
BC=sorted(BC,reverse=True,key=lambda x: x[1])
flag=0
t=0
for i in range(m):
  if flag==1:
    break
  for j in range(t,n):
    if BC[i][1]>A[j]:
      A[j]=BC[i][1]
      BC[i][0]-=1
      t=j+1
      if BC[i][0]==0:
        break
    else:
      flag=1
      break
print(sum(A))