import numpy as np



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



A = np.array([int(x) for x in input().split()],dtype=np.int64)

A.sort()



BC = np.array([[int(x) for x in input().split()] for _ in range(M)])

B = BC[:,0]

C = BC[:,1]



idx = C.argsort()

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



answer = A.sum()

print(answer)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from operator import itemgetter



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

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

m = list(map(int,read().split()))

BC = list(zip(m,m))



BC.sort(key = itemgetter(1),reverse=True)



BC.append((N,-1))



change = []

for b,c in BC:

    change += [c] * b

    if len(change) > N:

        break



A += change

A.sort()

answer = sum(A[-N:])

print(answer)
import numpy as np

N, M = list(map(int, input().split()))
A = np.array([int(x) for x in input().split()], dtype=np.int64)
A.sort()
BC = np.array([[int(x) for x in input().split()] for _ in range(M)])
B = BC[:, 0]
C = BC[:, 1]
idx = C.argsort()
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
answer = A.sum()
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter

N, M = list(map(int, readline().split()))
A = list(map(int, readline().split()))
m = list(map(int, read().split()))
BC = list(zip(m, m))
BC.sort(key=itemgetter(1), reverse=True)
BC.append((N, -1))
change = []
for b, c in BC:
    change += [c] * b
    if len(change) > N:
        break
A += change
A.sort()
answer = sum(A[-N:])
print(answer)

-import numpy as np +import sys -N, M = list(map(int, input().split())) -A = np.array([int(x) for x in input().split()], dtype=np.int64) +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +from operator import itemgetter + +N, M = list(map(int, readline().split())) +A = list(map(int, readline().split())) +m = list(map(int, read().split())) +BC = list(zip(m, m)) +BC.sort(key=itemgetter(1), reverse=True) +BC.append((N, -1)) +change = [] +for b, c in BC: +    change += [c] * b +    if len(change) > N: +        break +A += change -BC = np.array([[int(x) for x in input().split()] for _ in range(M)]) -B = BC[:, 0] -C = BC[:, 1] -idx = C.argsort() -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 -answer = A.sum() +answer = sum(A[-N:])