n, m = list(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)))
from itertools import zip_longest



n, m = list(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)
n, m = list(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)))

from itertools import zip_longest

n, m = list(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 + -BC.sort(key=lambda k: -k[1]) +BC.sort(key=lambda x: -x[1]) -cnt = 0 -for b, c in BC: -    for _ in range(b): -        stack.append(c) -        cnt += 1 -        if cnt > n: +i = 0 +while len(stack) < n and i < m: +    for _ in range(BC[i][0]): +        stack.append(BC[i][1]) +        if len(stack) >= n: -for i in range(min(n, len(stack))): -    if A[i] < stack[i]: -        A[i] = stack[i] -    else: -        break -print((sum(A))) +    i += 1 +ans = 0 +for a, s in zip_longest(A, stack, fillvalue=0): +    ans += max(a, s) +print(ans)