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

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

A.sort()

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

BC.sort(key = lambda x:-x[1])



index = 0

l = len(A)



for i in range(len(BC)):

    for j in range(BC[i][0]):

        if index == l or A[index] >= BC[i][1]:

            break

        else:

            A[index] = BC[i][1]

            index += 1



print((sum(A)))

    

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

A = [int(_) for _  in input().split()]

BC = []

count = 0

s = 0

D = []

for i in range(M):

    x,y = list(map(int,input().split()))

    BC.append([x,y])

A.sort()

BC.sort(key = lambda x:-x[1])

while s+BC[count][0] <= N:

    s += BC[count][0]

    for i in range(BC[count][0]):

        D.append(BC[count][1])

    if count == M-1:

        break

    else:

        count += 1

if count != M-1:

    for i in range(N-s):

        D.append(BC[count][1])

index = 0

while D[index] - A[index] > 0 :

    A[index] = D[index]

    if index == len(D)-1:

        break

    else:

        index += 1

print((sum(A)))
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
BC = [list(map(int, input().split())) for i in range(M)]
BC.sort(key=lambda x: -x[1])
index = 0
l = len(A)
for i in range(len(BC)):
    for j in range(BC[i][0]):
        if index == l or A[index] >= BC[i][1]:
            break
        else:
            A[index] = BC[i][1]
            index += 1
print((sum(A)))

N, M = list(map(int, input().split()))
A = [int(_) for _ in input().split()]
BC = []
count = 0
s = 0
D = []
for i in range(M):
    x, y = list(map(int, input().split()))
    BC.append([x, y])
A.sort()
BC.sort(key=lambda x: -x[1])
while s + BC[count][0] <= N:
    s += BC[count][0]
    for i in range(BC[count][0]):
        D.append(BC[count][1])
    if count == M - 1:
        break
    else:
        count += 1
if count != M - 1:
    for i in range(N - s):
        D.append(BC[count][1])
index = 0
while D[index] - A[index] > 0:
    A[index] = D[index]
    if index == len(D) - 1:
        break
    else:
        index += 1
print((sum(A)))

-A = list(map(int, input().split())) +A = [int(_) for _ in input().split()] +BC = [] +count = 0 +s = 0 +D = [] +for i in range(M): +    x, y = list(map(int, input().split())) +    BC.append([x, y]) -BC = [list(map(int, input().split())) for i in range(M)] +while s + BC[count][0] <= N: +    s += BC[count][0] +    for i in range(BC[count][0]): +        D.append(BC[count][1]) +    if count == M - 1: +        break +    else: +        count += 1 +if count != M - 1: +    for i in range(N - s): +        D.append(BC[count][1]) -l = len(A) -for i in range(len(BC)): -    for j in range(BC[i][0]): -        if index == l or A[index] >= BC[i][1]: -            break -        else: -            A[index] = BC[i][1] -            index += 1 +while D[index] - A[index] > 0: +    A[index] = D[index] +    if index == len(D) - 1: +        break +    else: +        index += 1