import numpy as np

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

a=np.array([int(i) for i in input().split()])

bc=np.array([[int(i) for i in input().split()] for j in range(m)])



a.sort()

b=bc[:,0]

c=bc[:,1]



idx=np.argsort(c)

b=b[idx][::-1]

c=c[idx][::-1]



p=0

for b,c in zip(b,c):

    a[p:p+b]=np.maximum(a[p:p+b],c)

    p+=b

    

    

print((a.sum()))
from heapq import heappop,heappush

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

a=[int(i) for i in input().split()]

a.sort()

bc=[[int(i) for i in input().split()]for j in range(m)]

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



ans=[]

for b,c in bc:    

    while b>0 and a: 

        x = heappop(a)

        if x<c:

            ans.append(c)

            b-=1

        else:

            ans.append(x)

print((sum(ans)+sum(a)))
import numpy as np

n, m = list(map(int, input().split()))
a = np.array([int(i) for i in input().split()])
bc = np.array([[int(i) for i in input().split()] for j in range(m)])
a.sort()
b = bc[:, 0]
c = bc[:, 1]
idx = np.argsort(c)
b = b[idx][::-1]
c = c[idx][::-1]
p = 0
for b, c in zip(b, c):
    a[p : p + b] = np.maximum(a[p : p + b], c)
    p += b
print((a.sum()))

from heapq import heappop, heappush

n, m = list(map(int, input().split()))
a = [int(i) for i in input().split()]
a.sort()
bc = [[int(i) for i in input().split()] for j in range(m)]
bc = sorted(bc, key=lambda x: x[1], reverse=True)
ans = []
for b, c in bc:
    while b > 0 and a:
        x = heappop(a)
        if x < c:
            ans.append(c)
            b -= 1
        else:
            ans.append(x)
print((sum(ans) + sum(a)))

-import numpy as np +from heapq import heappop, heappush -a = np.array([int(i) for i in input().split()]) -bc = np.array([[int(i) for i in input().split()] for j in range(m)]) +a = [int(i) for i in input().split()] -b = bc[:, 0] -c = bc[:, 1] -idx = np.argsort(c) -b = b[idx][::-1] -c = c[idx][::-1] -p = 0 -for b, c in zip(b, c): -    a[p : p + b] = np.maximum(a[p : p + b], c) -    p += b -print((a.sum())) +bc = [[int(i) for i in input().split()] for j in range(m)] +bc = sorted(bc, key=lambda x: x[1], reverse=True) +ans = [] +for b, c in bc: +    while b > 0 and a: +        x = heappop(a) +        if x < c: +            ans.append(c) +            b -= 1 +        else: +            ans.append(x) +print((sum(ans) + sum(a)))