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

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

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



P = sorted(([[1,A[i]] for i in range(N)] + L),key=lambda x: x[1],reverse=True)



ans = 0

rest = N



for cost,value in P :

    K = min(cost, rest)

    K = max(0,K)

    ans += K * value

    rest -= cost



print(ans)

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



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



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



for i in range(N) :

    L.append([1,A[i]])



L = sorted(L, key=lambda x: x[1], reverse=True)



ans = 0



for i in range(len(L)) :

    number, point = L[i]

    

    if number > N :

        number = N

    

    ans += number * point

    N -= number

    

print(ans)

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(M)]
P = sorted(([[1, A[i]] for i in range(N)] + L), key=lambda x: x[1], reverse=True)
ans = 0
rest = N
for cost, value in P:
    K = min(cost, rest)
    K = max(0, K)
    ans += K * value
    rest -= cost
print(ans)

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(M)]
for i in range(N):
    L.append([1, A[i]])
L = sorted(L, key=lambda x: x[1], reverse=True)
ans = 0
for i in range(len(L)):
    number, point = L[i]
    if number > N:
        number = N
    ans += number * point
    N -= number
print(ans)

-P = sorted(([[1, A[i]] for i in range(N)] + L), key=lambda x: x[1], reverse=True) +for i in range(N): +    L.append([1, A[i]]) +L = sorted(L, key=lambda x: x[1], reverse=True) -rest = N -for cost, value in P: -    K = min(cost, rest) -    K = max(0, K) -    ans += K * value -    rest -= cost +for i in range(len(L)): +    number, point = L[i] +    if number > N: +        number = N +    ans += number * point +    N -= number