from itertools import zip_longest

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 x: -x[1])

stack = []
i = 0
while len(stack) < n and i < m:
  for _ in range(BC[i][0]):
    stack.append(BC[i][1])
    if len(stack) >= n:
      break
  i += 1

ans = 0
for a, s in zip_longest(A, stack, fillvalue=0):
  ans += max(a, s)

print(ans) from itertools import zip_longest 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 x: -x[1]) BC.sort BC sort key=lambda x: -x[1] key lambda x: -x[1] -x[1] x[1] x 1 x stack = [] stack [] i = 0 i 0 while len(stack) < n and i < m:
  for _ in range(BC[i][0]):
    stack.append(BC[i][1])
    if len(stack) >= n:
      break
  i += 1 len(stack) < n and i < m len(stack) < n len(stack) len stack n i < m i m for _ in range(BC[i][0]):
    stack.append(BC[i][1])
    if len(stack) >= n:
      break
   _ range(BC[i][0]) range BC[i][0] [i] BC i 0 stack.append(BC[i][1]) stack.append stack append BC[i][1] [i] BC i 1 if len(stack) >= n:
      break
   len(stack) >= n len(stack) len stack n break i += 1 i 1 ans = 0 ans 0 for a, s in zip_longest(A, stack, fillvalue=0):
  ans += max(a, s) a s zip_longest(A, stack, fillvalue=0) zip_longest A stack fillvalue=0 fillvalue 0 ans += max(a, s) ans max(a, s) max a s print(ans) print ans A = list(map(int, input().split())) list(map(int, input().split())) A ans = 0 0 ans n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m i += 1 1 i BC = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] BC stack = [] [] stack i = 0 0 i ans += max(a, s) max(a, s) ans
from itertools import zip_longest

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 x: -x[1])

stack = []
i = 0
while len(stack) < n and i < m:
  for _ in range(BC[i][0]):
    stack.append(BC[i][1])
    if len(stack) >= n:
      break
  i += 1

ans = 0
for a, s in zip_longest(A, stack, fillvalue=0):
  ans += max(a, s)

print(ans)