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])



memo = []



limit = 0



for i in range(m):

    a += [bc[i][1]]*bc[i][0]

    limit += bc[i][0]

    if limit >= n:

        break



a.sort(reverse=True)



print((sum(a[:n])))
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()))
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])
memo = []
limit = 0
for i in range(m):
    a += [bc[i][1]] * bc[i][0]
    limit += bc[i][0]
    if limit >= n:
        break
a.sort(reverse=True)
print((sum(a[:n])))

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)))

+import heapq + -memo = [] -limit = 0 +heapq.heapify(a) -    a += [bc[i][1]] * bc[i][0] -    limit += bc[i][0] -    if limit >= n: +    count = 0 +    if bc[i][1] < a[0]: -a.sort(reverse=True) -print((sum(a[:n]))) +    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)))