from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [(A[i], 1) for i in range(N)]

changes = [None] * M
for i in range(M):
    b, c = map(int, input().split())
    changes[i] = (c, b)

allVals = A + changes

allVals.sort(key = lambda x:x[0], reverse = True)
# print(allVals)

i = 0
j = -1
res = 0
while True:
    j += 1
    res += allVals[j][0] * allVals[j][1]
    i += allVals[j][1]

    if i >= N:
        res -= allVals[j][0] * (i - N)
        break



print(res) from collections import defaultdict N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split (A[i], 1) for i in range(N) for i in range(N) i range(N) range N for i in range(N) (A[i], 1) A[i] A i 1 A = [(A[i], 1) for i in range(N)] A [(A[i], 1) for i in range(N)] changes = [None] * M changes [None] * M [None] None M for i in range(M):
    b, c = map(int, input().split())
    changes[i] = (c, b) i range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c changes[i] = (c, b) changes[i] changes i (c, b) c b allVals = A + changes allVals A + changes A changes allVals.sort(key = lambda x:x[0], reverse = True) allVals.sort allVals sort key = lambda x:x[0] key lambda x:x[0] x[0] x 0 x reverse = True reverse True i = 0 i 0 j = -1 j -1 res = 0 res 0 while True:
    j += 1
    res += allVals[j][0] * allVals[j][1]
    i += allVals[j][1]

    if i >= N:
        res -= allVals[j][0] * (i - N)
        break True j += 1 j 1 res += allVals[j][0] * allVals[j][1] res allVals[j][0] * allVals[j][1] allVals[j][0] [j] allVals j 0 allVals[j][1] [j] allVals j 1 i += allVals[j][1] i allVals[j][1] [j] allVals j 1 if i >= N:
        res -= allVals[j][0] * (i - N)
        break i >= N i N res -= allVals[j][0] * (i - N) res allVals[j][0] * (i - N) allVals[j][0] [j] allVals j 0 i - N i N break print(res) print res A = list(map(int, input().split())) list(map(int, input().split())) A c = map(int, input().split()) map(int, input().split()) c i = 0 0 i b, c = map(int, input().split()) map(int, input().split()) b res += allVals[j][0] * allVals[j][1] allVals[j][0] * allVals[j][1] res i += allVals[j][1] allVals[j][1] i A = [(A[i], 1) for i in range(N)] [(A[i], 1) for i in range(N)] A allVals = A + changes A + changes allVals j = -1 -1 j N, M = map(int, input().split()) map(int, input().split()) N res -= allVals[j][0] * (i - N) allVals[j][0] * (i - N) res M = map(int, input().split()) map(int, input().split()) M changes = [None] * M [None] * M changes res = 0 0 res j += 1 1 j
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [(A[i], 1) for i in range(N)]

changes = [None] * M
for i in range(M):
    b, c = map(int, input().split())
    changes[i] = (c, b)

allVals = A + changes

allVals.sort(key = lambda x:x[0], reverse = True)
# print(allVals)

i = 0
j = -1
res = 0
while True:
    j += 1
    res += allVals[j][0] * allVals[j][1]
    i += allVals[j][1]

    if i >= N:
        res -= allVals[j][0] * (i - N)
        break



print(res)
