N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
B=[list(map(int,input().split())) for _ in range(M)]
B.sort(key=lambda x:-x[1])
i,j=0,0
while i<=N-1:
  for l in range(B[j][0]):
    if A[i]>=B[j][1]:
      print(sum(A))
      exit()
    A[i]=B[j][1]
    i+=1
    if i==N:
      print(sum(A))
      exit()
  j+=1
  if j==M:
    print(sum(A))
    exit()
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 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 B=[list(map(int,input().split())) for _ in range(M)] B [list(map(int,input().split())) for _ in range(M)] B.sort(key=lambda x:-x[1]) B.sort B sort key=lambda x:-x[1] key lambda x:-x[1] -x[1] x[1] x 1 x i,j=0,0 i 0 j 0 while i<=N-1:
  for l in range(B[j][0]):
    if A[i]>=B[j][1]:
      print(sum(A))
      exit()
    A[i]=B[j][1]
    i+=1
    if i==N:
      print(sum(A))
      exit()
  j+=1
  if j==M:
    print(sum(A))
    exit() i<=N-1 i N-1 N 1 for l in range(B[j][0]):
    if A[i]>=B[j][1]:
      print(sum(A))
      exit()
    A[i]=B[j][1]
    i+=1
    if i==N:
      print(sum(A))
      exit()
   l range(B[j][0]) range B[j][0] [j] B j 0 if A[i]>=B[j][1]:
      print(sum(A))
      exit()
     A[i]>=B[j][1] A[i] A i B[j][1] [j] B j 1 print(sum(A)) print sum(A) sum A exit() exit A[i]=B[j][1] A[i] A i B[j][1] [j] B j 1 i+=1 i 1 if i==N:
      print(sum(A))
      exit()
   i==N i N print(sum(A)) print sum(A) sum A exit() exit j+=1 j 1 if j==M:
    print(sum(A))
    exit() j==M j M print(sum(A)) print sum(A) sum A exit() exit print(sum(A)) print sum(A) sum A M=map(int,input().split()) map(int,input().split()) M i,j=0,0 0 i j+=1 1 j i+=1 1 i N,M=map(int,input().split()) map(int,input().split()) N j=0,0 0 j A=list(map(int,input().split())) list(map(int,input().split())) A B=[list(map(int,input().split())) for _ in range(M)] [list(map(int,input().split())) for _ in range(M)] B
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
B=[list(map(int,input().split())) for _ in range(M)]
B.sort(key=lambda x:-x[1])
i,j=0,0
while i<=N-1:
  for l in range(B[j][0]):
    if A[i]>=B[j][1]:
      print(sum(A))
      exit()
    A[i]=B[j][1]
    i+=1
    if i==N:
      print(sum(A))
      exit()
  j+=1
  if j==M:
    print(sum(A))
    exit()
print(sum(A))