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

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

A.sort()

bc = [list(map(int,input().split())) for _ in range(m)]



bc.sort(key=lambda x:x[1],reverse=1)



i = 0#bcの添え字

j = 0#Aの添え字

while 1:

	if i >= m or j >= n:

		#print('iかjが超えた！')

		break

	if bc[i][1] < A[j]:

		#print('Aでっか')

		break

	for k in range(bc[i][0]):

		#print(i,j,k)

		A[j] = bc[i][1]

		j+=1

		if j >= n:

			#print('for文内、jが超えた')

			break

		if A[j] > bc[i][1]:

			#print('for文内、Aでっか')

			break

	i+=1

# print(A)

print((sum(A)))
from heapq import heapify,heappop,heappush

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

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

heapify(A)

bc = [list(map(int,input().split())) for i in range(m)]

bc.sort(key=lambda x:x[1],reverse=1)



flag = 0

# print(A)

for b,c in bc:

	if flag:

		break

	for i in range(b):

		a = heappop(A)

		if c <= a:

			heappush(A,a)

			flag = 1

			break

		else:

			heappush(A,c)

print((sum(A)))
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=1)
i = 0  # bcの添え字
j = 0  # Aの添え字
while 1:
    if i >= m or j >= n:
        # print('iかjが超えた！')
        break
    if bc[i][1] < A[j]:
        # print('Aでっか')
        break
    for k in range(bc[i][0]):
        # print(i,j,k)
        A[j] = bc[i][1]
        j += 1
        if j >= n:
            # print('for文内、jが超えた')
            break
        if A[j] > bc[i][1]:
            # print('for文内、Aでっか')
            break
    i += 1
# print(A)
print((sum(A)))

from heapq import heapify, heappop, heappush

n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
heapify(A)
bc = [list(map(int, input().split())) for i in range(m)]
bc.sort(key=lambda x: x[1], reverse=1)
flag = 0
# print(A)
for b, c in bc:
    if flag:
        break
    for i in range(b):
        a = heappop(A)
        if c <= a:
            heappush(A, a)
            flag = 1
            break
        else:
            heappush(A, c)
print((sum(A)))

+from heapq import heapify, heappop, heappush + -A.sort() -bc = [list(map(int, input().split())) for _ in range(m)] +heapify(A) +bc = [list(map(int, input().split())) for i in range(m)] -i = 0  # bcの添え字 -j = 0  # Aの添え字 -while 1: -    if i >= m or j >= n: -        # print('iかjが超えた！') +flag = 0 +# print(A) +for b, c in bc: +    if flag: -    if bc[i][1] < A[j]: -        # print('Aでっか') -        break -    for k in range(bc[i][0]): -        # print(i,j,k) -        A[j] = bc[i][1] -        j += 1 -        if j >= n: -            # print('for文内、jが超えた') +    for i in range(b): +        a = heappop(A) +        if c <= a: +            heappush(A, a) +            flag = 1 -        if A[j] > bc[i][1]: -            # print('for文内、Aでっか') -            break -    i += 1 -# print(A) +        else: +            heappush(A, c)