from collections import Counter

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

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



X = Counter(A)

for i in range(M):

    B, C = list(map(int, input().split()))

    X[C] += B



Z = []

for key, value in list(X.items()):

    Z.append((key, value))



Z.sort(key=lambda x: x[0], reverse=True)



ans = 0

cnt = 0



for value, key in Z:

    if cnt + key <= N:

        ans += key * value

        cnt += key

    else:

        ans += (N - cnt) * value

        break



print(ans)

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

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

query = []

for i in range(M):

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

    query.append([b, c])

query.sort(key=lambda q: q[1], reverse=True)





i = 0

for b, c in query:

    while i < N and b > 0:

        if A[i] < c:

            A[i] = c

            b -= 1

        i += 1



print((sum(A)))

from collections import Counter

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
X = Counter(A)
for i in range(M):
    B, C = list(map(int, input().split()))
    X[C] += B
Z = []
for key, value in list(X.items()):
    Z.append((key, value))
Z.sort(key=lambda x: x[0], reverse=True)
ans = 0
cnt = 0
for value, key in Z:
    if cnt + key <= N:
        ans += key * value
        cnt += key
    else:
        ans += (N - cnt) * value
        break
print(ans)

N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
query = []
for i in range(M):
    b, c = list(map(int, input().split()))
    query.append([b, c])
query.sort(key=lambda q: q[1], reverse=True)
i = 0
for b, c in query:
    while i < N and b > 0:
        if A[i] < c:
            A[i] = c
            b -= 1
        i += 1
print((sum(A)))

-from collections import Counter - -A = list(map(int, input().split())) -X = Counter(A) +A = sorted(list(map(int, input().split()))) +query = [] -    B, C = list(map(int, input().split())) -    X[C] += B -Z = [] -for key, value in list(X.items()): -    Z.append((key, value)) -Z.sort(key=lambda x: x[0], reverse=True) -ans = 0 -cnt = 0 -for value, key in Z: -    if cnt + key <= N: -        ans += key * value -        cnt += key -    else: -        ans += (N - cnt) * value -        break -print(ans) +    b, c = list(map(int, input().split())) +    query.append([b, c]) +query.sort(key=lambda q: q[1], reverse=True) +i = 0 +for b, c in query: +    while i < N and b > 0: +        if A[i] < c: +            A[i] = c +            b -= 1 +        i += 1 +print((sum(A)))