n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]

A.sort()
BC.sort(key=lambda k: -k[1])

stack = []
cnt = 0
for b, c in BC:
  for _ in range(b):
    stack.append(c)
    cnt += 1
    if cnt > n:
      break

for i in range(min(n, len(stack))):
  if A[i] < stack[i]:
    A[i] = stack[i]
  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 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)] A.sort() A.sort A sort BC.sort(key=lambda k: -k[1]) BC.sort BC sort key=lambda k: -k[1] key lambda k: -k[1] -k[1] k[1] k 1 k stack = [] stack [] cnt = 0 cnt 0 for b, c in BC:
  for _ in range(b):
    stack.append(c)
    cnt += 1
    if cnt > n:
      break b c BC for _ in range(b):
    stack.append(c)
    cnt += 1
    if cnt > n:
      break _ range(b) range b stack.append(c) stack.append stack append c cnt += 1 cnt 1 if cnt > n:
      break cnt > n cnt n break for i in range(min(n, len(stack))):
  if A[i] < stack[i]:
    A[i] = stack[i]
  else:
    break
     i range(min(n, len(stack))) range min(n, len(stack)) min n len(stack) len stack if A[i] < stack[i]:
    A[i] = stack[i]
  else:
    break
     A[i] < stack[i] A[i] A i stack[i] stack i A[i] = stack[i] A[i] A i stack[i] stack i break print(sum(A)) print sum(A) sum A cnt = 0 0 cnt m = map(int, input().split()) map(int, input().split()) m BC = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] BC A = list(map(int, input().split())) list(map(int, input().split())) A stack = [] [] stack cnt += 1 1 cnt n, m = map(int, input().split()) map(int, input().split()) n
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]

A.sort()
BC.sort(key=lambda k: -k[1])

stack = []
cnt = 0
for b, c in BC:
  for _ in range(b):
    stack.append(c)
    cnt += 1
    if cnt > n:
      break

for i in range(min(n, len(stack))):
  if A[i] < stack[i]:
    A[i] = stack[i]
  else:
    break
    
print(sum(A))