import heapq

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

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

heapq.heapify(a)

CB=[]

for _ in range(m):

    b, c = list(map(int, input().split()))

    CB.append((c, b))

CB.sort(reverse=True)



for c, b in CB:

    if a[0] >= c:

        break

    for _ in range(b):

        if a[0] >= c:

            break

        heapq.heappushpop(a, c)



print((sum(a)))
from operator import itemgetter

import heapq

import sys

input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)



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

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

heapq.heapify(A)



BC = [tuple(map(int, input().split())) for _ in range(M)]

BC.sort(reverse=True, key=itemgetter(1))



for b, c in BC:

    if A[0] < c:

        while b:

            heapq.heappushpop(A, c)

            b -= 1

    else:

        break



print((sum(A)))
import heapq

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
CB = []
for _ in range(m):
    b, c = list(map(int, input().split()))
    CB.append((c, b))
CB.sort(reverse=True)
for c, b in CB:
    if a[0] >= c:
        break
    for _ in range(b):
        if a[0] >= c:
            break
        heapq.heappushpop(a, c)
print((sum(a)))

from operator import itemgetter
import heapq
import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)
BC = [tuple(map(int, input().split())) for _ in range(M)]
BC.sort(reverse=True, key=itemgetter(1))
for b, c in BC:
    if A[0] < c:
        while b:
            heapq.heappushpop(A, c)
            b -= 1
    else:
        break
print((sum(A)))

+from operator import itemgetter +import sys -n, m = list(map(int, input().split())) -a = list(map(int, input().split())) -heapq.heapify(a) -CB = [] -for _ in range(m): -    b, c = list(map(int, input().split())) -    CB.append((c, b)) -CB.sort(reverse=True) -for c, b in CB: -    if a[0] >= c: +input = sys.stdin.buffer.readline +sys.setrecursionlimit(10**7) +N, M = list(map(int, input().split())) +A = list(map(int, input().split())) +heapq.heapify(A) +BC = [tuple(map(int, input().split())) for _ in range(M)] +BC.sort(reverse=True, key=itemgetter(1)) +for b, c in BC: +    if A[0] < c: +        while b: +            heapq.heappushpop(A, c) +            b -= 1 +    else: -    for _ in range(b): -        if a[0] >= c: -            break -        heapq.heappushpop(a, c) -print((sum(a))) +print((sum(A)))