import numpy as np

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

N = NM[0]

M = NM[1]

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

listBC =[]

while True:

    try:

        listBC.append(list(map(int,input().split())))

    except:

        break;

BC = np.array(listBC)

BCnum = np.argsort(BC[:,1])[::-1]

BC = BC[BCnum,:]



A.sort()

j=0

for i in range(len(A)):

    times = BC[j,0]

    if BC[j,0]==0:

        j+=1

        if j == BC.shape[0]:

            break

        times = BC[j,0]

    if A[i]<BC[j,1]:

        A[i]=BC[j,1]

        BC[j,0] += -1

output = sum(A)

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

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



from collections import Counter

D = dict(Counter(A))



for i in range(M):

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

    D[C]=D.get(C,0)+B



K = sorted(list(D.keys()),reverse=True)



out = 0

cnt = 0

now = 0

while cnt<=N-1:

    if D[K[now]]>0:

        out += K[now]

        D[K[now]] += -1

        cnt+=1

    else:

        now+=1

print(out)
import numpy as np

NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]
A = list(map(int, input().split()))
listBC = []
while True:
    try:
        listBC.append(list(map(int, input().split())))
    except:
        break
BC = np.array(listBC)
BCnum = np.argsort(BC[:, 1])[::-1]
BC = BC[BCnum, :]
A.sort()
j = 0
for i in range(len(A)):
    times = BC[j, 0]
    if BC[j, 0] == 0:
        j += 1
        if j == BC.shape[0]:
            break
        times = BC[j, 0]
    if A[i] < BC[j, 1]:
        A[i] = BC[j, 1]
        BC[j, 0] += -1
output = sum(A)
print(output)

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
from collections import Counter

D = dict(Counter(A))
for i in range(M):
    B, C = list(map(int, input().split()))
    D[C] = D.get(C, 0) + B
K = sorted(list(D.keys()), reverse=True)
out = 0
cnt = 0
now = 0
while cnt <= N - 1:
    if D[K[now]] > 0:
        out += K[now]
        D[K[now]] += -1
        cnt += 1
    else:
        now += 1
print(out)

-import numpy as np +N, M = list(map(int, input().split())) +A = list(map(int, input().split())) +from collections import Counter -NM = list(map(int, input().split())) -N = NM[0] -M = NM[1] -A = list(map(int, input().split())) -listBC = [] -while True: -    try: -        listBC.append(list(map(int, input().split()))) -    except: -        break -BC = np.array(listBC) -BCnum = np.argsort(BC[:, 1])[::-1] -BC = BC[BCnum, :] -A.sort() -j = 0 -for i in range(len(A)): -    times = BC[j, 0] -    if BC[j, 0] == 0: -        j += 1 -        if j == BC.shape[0]: -            break -        times = BC[j, 0] -    if A[i] < BC[j, 1]: -        A[i] = BC[j, 1] -        BC[j, 0] += -1 -output = sum(A) -print(output) +D = dict(Counter(A)) +for i in range(M): +    B, C = list(map(int, input().split())) +    D[C] = D.get(C, 0) + B +K = sorted(list(D.keys()), reverse=True) +out = 0 +cnt = 0 +now = 0 +while cnt <= N - 1: +    if D[K[now]] > 0: +        out += K[now] +        D[K[now]] += -1 +        cnt += 1 +    else: +        now += 1 +print(out)