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

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

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

A.sort()

idx = 0



for b, c in sorted(X, key=lambda x: -x[1]):

    for j in range(idx, min(N, idx + b)):

        if A[j] < c:

            A[j] = c

    idx += b

print((sum(A)))

    


from collections import Counter

from heapq import heappop, heappush



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

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

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



pq = []

ctr = Counter(A)

for val, cnt in list(ctr.items()):

    heappush(pq, (-val, cnt))



for b, c in X:

    heappush(pq, (-c, b))



cnt = 0

ans = 0

while cnt < N:

    val, c = heappop(pq)

    ans += val * min(c, N - cnt)

    cnt += c



print((-ans))

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
A.sort()
idx = 0
for b, c in sorted(X, key=lambda x: -x[1]):
    for j in range(idx, min(N, idx + b)):
        if A[j] < c:
            A[j] = c
    idx += b
print((sum(A)))

from collections import Counter
from heapq import heappop, heappush

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
pq = []
ctr = Counter(A)
for val, cnt in list(ctr.items()):
    heappush(pq, (-val, cnt))
for b, c in X:
    heappush(pq, (-c, b))
cnt = 0
ans = 0
while cnt < N:
    val, c = heappop(pq)
    ans += val * min(c, N - cnt)
    cnt += c
print((-ans))

+from collections import Counter +from heapq import heappop, heappush + -A.sort() -idx = 0 -for b, c in sorted(X, key=lambda x: -x[1]): -    for j in range(idx, min(N, idx + b)): -        if A[j] < c: -            A[j] = c -    idx += b -print((sum(A))) +pq = [] +ctr = Counter(A) +for val, cnt in list(ctr.items()): +    heappush(pq, (-val, cnt)) +for b, c in X: +    heappush(pq, (-c, b)) +cnt = 0 +ans = 0 +while cnt < N: +    val, c = heappop(pq) +    ans += val * min(c, N - cnt) +    cnt += c +print((-ans))