import sys
N, M = map(int, input().split())
A = list(map(int, input().split()))
card = [ list(map(int, i.rstrip().split())) for i in sys.stdin.readlines()]
card = sorted(card, key=lambda x:x[1], reverse=True)
A = sorted(A)
i = 0
for b, c in card:
  for _ in range(b):
    if i >= N:
      break
    elif A[i] >= c:
      break
    else:
      A[i] = c
      i += 1
print(sum(A)) import sys sys 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, i.rstrip().split())) for i in sys.stdin.readlines() for i in sys.stdin.readlines() i sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines for i in sys.stdin.readlines() list(map(int, i.rstrip().split())) list map(int, i.rstrip().split()) map int i.rstrip().split() i.rstrip().split i.rstrip() i.rstrip i rstrip split card = [ list(map(int, i.rstrip().split())) for i in sys.stdin.readlines()] card [ list(map(int, i.rstrip().split())) for i in sys.stdin.readlines()] card = sorted(card, key=lambda x:x[1], reverse=True) card sorted(card, key=lambda x:x[1], reverse=True) sorted card key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse=True reverse True A = sorted(A) A sorted(A) sorted A i = 0 i 0 for b, c in card:
  for _ in range(b):
    if i >= N:
      break
    elif A[i] >= c:
      break
    else:
      A[i] = c
      i += 1 b c card for _ in range(b):
    if i >= N:
      break
    elif A[i] >= c:
      break
    else:
      A[i] = c
      i += 1 _ range(b) range b if i >= N:
      break
    elif A[i] >= c:
      break
    else:
      A[i] = c
      i += 1 i >= N i N break elif A[i] >= c:
      break
     A[i] >= c A[i] A i c break A[i] = c A[i] A i c i += 1 i 1 print(sum(A)) print sum(A) sum A card = [ list(map(int, i.rstrip().split())) for i in sys.stdin.readlines()] [ list(map(int, i.rstrip().split())) for i in sys.stdin.readlines()] card N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M i = 0 0 i i += 1 1 i A = sorted(A) sorted(A) A card = sorted(card, key=lambda x:x[1], reverse=True) sorted(card, key=lambda x:x[1], reverse=True) card A = list(map(int, input().split())) list(map(int, input().split())) A
import sys
N, M = map(int, input().split())
A = list(map(int, input().split()))
card = [ list(map(int, i.rstrip().split())) for i in sys.stdin.readlines()]
card = sorted(card, key=lambda x:x[1], reverse=True)
A = sorted(A)
i = 0
for b, c in card:
  for _ in range(b):
    if i >= N:
      break
    elif A[i] >= c:
      break
    else:
      A[i] = c
      i += 1
print(sum(A))