import heapq



n,m = list(map(int,input().split()))



a = list(map(int,input().split()))

bc = []

for _ in range(m):

    b, c = (int(x) for x in input().split())

    bc.append([b, c])

bc = sorted(bc, key=lambda x: -x[1])



heapq.heapify(a)



for i in range(m):

    count = 0

    if bc[i][1] < a[0]:

        break

    while a[0] < bc[i][1] and count < bc[i][0]:

        heapq.heappop(a)

        heapq.heappush(a,bc[i][1])

        count += 1

print((sum(a)))
N,M = list(map(int,input().split()))



A = list(map(int,input().split()))

A.sort(reverse=True)

BC = []

for _ in range(M):

    B, C = (int(x) for x in input().split())

    BC.append([B, C])

BC = sorted(BC, key=lambda x: -x[1])



index = 0



ans = 0



while index < M and len(A) and A[-1] < BC[index][1]:

    b, c = BC[index]

    count = 0

    while len(A) and A[-1] < c and count < b:

        A.pop()

        ans += c

        count += 1

    index += 1

print((sum(A)+ans))
import heapq

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for _ in range(m):
    b, c = (int(x) for x in input().split())
    bc.append([b, c])
bc = sorted(bc, key=lambda x: -x[1])
heapq.heapify(a)
for i in range(m):
    count = 0
    if bc[i][1] < a[0]:
        break
    while a[0] < bc[i][1] and count < bc[i][0]:
        heapq.heappop(a)
        heapq.heappush(a, bc[i][1])
        count += 1
print((sum(a)))

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
BC = []
for _ in range(M):
    B, C = (int(x) for x in input().split())
    BC.append([B, C])
BC = sorted(BC, key=lambda x: -x[1])
index = 0
ans = 0
while index < M and len(A) and A[-1] < BC[index][1]:
    b, c = BC[index]
    count = 0
    while len(A) and A[-1] < c and count < b:
        A.pop()
        ans += c
        count += 1
    index += 1
print((sum(A) + ans))

-import heapq - -n, m = list(map(int, input().split())) -a = list(map(int, input().split())) -bc = [] -for _ in range(m): -    b, c = (int(x) for x in input().split()) -    bc.append([b, c]) -bc = sorted(bc, key=lambda x: -x[1]) -heapq.heapify(a) -for i in range(m): +N, M = list(map(int, input().split())) +A = list(map(int, input().split())) +A.sort(reverse=True) +BC = [] +for _ in range(M): +    B, C = (int(x) for x in input().split()) +    BC.append([B, C]) +BC = sorted(BC, key=lambda x: -x[1]) +index = 0 +ans = 0 +while index < M and len(A) and A[-1] < BC[index][1]: +    b, c = BC[index] -    if bc[i][1] < a[0]: -        break -    while a[0] < bc[i][1] and count < bc[i][0]: -        heapq.heappop(a) -        heapq.heappush(a, bc[i][1]) +    while len(A) and A[-1] < c and count < b: +        A.pop() +        ans += c -print((sum(a))) +    index += 1 +print((sum(A) + ans))