N,M=map(int,input().split())
import heapq
A=list(map(int,input().split()))
heapq.heapify(A)
BC=[]
for i in range(M):
  B,C=map(int,input().split())
  BC.append((B,C))
BC.sort(key=lambda x:x[1],reverse=True)
import bisect
A.sort()
now=0
D=[0]*N
for i in range(M):
  B=BC[i][0]
  C=BC[i][1]
  for j in range(now,min(now+B,N)):
    D[j]=C
  now+=B
  if now>N-1:
    break

for i in range(N):
  a=A[i]
  d=D[i]
  if d>a:
    A[i]=d
  else:
    break
print(sum(A)) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M import heapq heapq A=list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split heapq.heapify(A) heapq.heapify heapq heapify A BC=[] BC [] for i in range(M):
  B,C=map(int,input().split())
  BC.append((B,C)) i range(M) range M B,C=map(int,input().split()) B map(int,input().split()) map int input().split() ().split () input split C BC.append((B,C)) BC.append BC append (B,C) B C 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 import bisect bisect A.sort() A.sort A sort now=0 now 0 D=[0]*N D [0]*N [0] 0 N for i in range(M):
  B=BC[i][0]
  C=BC[i][1]
  for j in range(now,min(now+B,N)):
    D[j]=C
  now+=B
  if now>N-1:
    break i range(M) range M B=BC[i][0] B BC[i][0] [i] BC i 0 C=BC[i][1] C BC[i][1] [i] BC i 1 for j in range(now,min(now+B,N)):
    D[j]=C
   j range(now,min(now+B,N)) range now min(now+B,N) min now+B now B N D[j]=C D[j] D j C now+=B now B if now>N-1:
    break now>N-1 now N-1 N 1 break for i in range(N):
  a=A[i]
  d=D[i]
  if d>a:
    A[i]=d
  else:
    break i range(N) range N a=A[i] a A[i] A i d=D[i] d D[i] D i if d>a:
    A[i]=d
  else:
    break d>a d a A[i]=d A[i] A i d break print(sum(A)) print sum(A) sum A N,M=map(int,input().split()) map(int,input().split()) N B=BC[i][0] BC[i][0] B B,C=map(int,input().split()) map(int,input().split()) B M=map(int,input().split()) map(int,input().split()) M D=[0]*N [0]*N D a=A[i] A[i] a BC=[] [] BC C=map(int,input().split()) map(int,input().split()) C now+=B B now A=list(map(int,input().split())) list(map(int,input().split())) A d=D[i] D[i] d now=0 0 now C=BC[i][1] BC[i][1] C
N,M=map(int,input().split())
import heapq
A=list(map(int,input().split()))
heapq.heapify(A)
BC=[]
for i in range(M):
  B,C=map(int,input().split())
  BC.append((B,C))
BC.sort(key=lambda x:x[1],reverse=True)
import bisect
A.sort()
now=0
D=[0]*N
for i in range(M):
  B=BC[i][0]
  C=BC[i][1]
  for j in range(now,min(now+B,N)):
    D[j]=C
  now+=B
  if now>N-1:
    break

for i in range(N):
  a=A[i]
  d=D[i]
  if d>a:
    A[i]=d
  else:
    break
print(sum(A))