import sys

input = sys.stdin.readline

N, M = [int(x) for x in input().split()]

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

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

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

N2 = N

D = []

for i in BC:

    temp = min(N2,i[0])

    D += [i[1]] * temp

    N2 -= temp

    if not N2:

        break

A += D

A.sort()

print((sum(A[len(A) - N:])))
import sys

input = lambda : sys.stdin.readline().rstrip()



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

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

bc = []

for _ in range(m):

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

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

cnt = n

for b, c in bc:

    if cnt <= b:

        for i in range(cnt):

            a.append(c)

        break

    else:

        for i in range(b):

            a.append(c)

        cnt -= b

a = sorted(a, reverse=True)

print((sum(a[:n])))



import sys

input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
BC = [[int(x) for x in input().split()] for _ in range(M)]
BC = sorted(BC, reverse=True, key=lambda x: x[1])
N2 = N
D = []
for i in BC:
    temp = min(N2, i[0])
    D += [i[1]] * temp
    N2 -= temp
    if not N2:
        break
A += D
A.sort()
print((sum(A[len(A) - N :])))

import sys

input = lambda: sys.stdin.readline().rstrip()
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for _ in range(m):
    bc.append(list(map(int, input().split())))
bc = sorted(bc, reverse=True, key=lambda x: x[1])
cnt = n
for b, c in bc:
    if cnt <= b:
        for i in range(cnt):
            a.append(c)
        break
    else:
        for i in range(b):
            a.append(c)
        cnt -= b
a = sorted(a, reverse=True)
print((sum(a[:n])))

-input = sys.stdin.readline -N, M = [int(x) for x in input().split()] -A = [int(x) for x in input().split()] -BC = [[int(x) for x in input().split()] for _ in range(M)] -BC = sorted(BC, reverse=True, key=lambda x: x[1]) -N2 = N -D = [] -for i in BC: -    temp = min(N2, i[0]) -    D += [i[1]] * temp -    N2 -= temp -    if not N2: +input = lambda: sys.stdin.readline().rstrip() +n, m = list(map(int, input().split())) +a = list(map(int, input().split())) +bc = [] +for _ in range(m): +    bc.append(list(map(int, input().split()))) +bc = sorted(bc, reverse=True, key=lambda x: x[1]) +cnt = n +for b, c in bc: +    if cnt <= b: +        for i in range(cnt): +            a.append(c) -A += D -A.sort() -print((sum(A[len(A) - N :]))) +    else: +        for i in range(b): +            a.append(c) +        cnt -= b +a = sorted(a, reverse=True) +print((sum(a[:n])))