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

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

bc = [list(map(int, input().split())) for _ in range(m)]



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

a.sort()



i = 0

for b, c in bc:

    for _ in range(b):

        if i < n and a[i] < c:

            a[i] = c

            i += 1

        else:

            break



ans = sum(a)

print(ans)

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

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

bc = [list(map(int, input().split())) for _ in range(m)]



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



li = []

l = 0

i = 0

while i < m and l < n:

    b, c = bc[i]

    li += [c] * b

    i += 1

    l += b



a += li

a.sort(reverse=True)

ans = sum(a[:n])

print(ans)

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

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(reverse=True, key=lambda x: x[1])
li = []
l = 0
i = 0
while i < m and l < n:
    b, c = bc[i]
    li += [c] * b
    i += 1
    l += b
a += li
a.sort(reverse=True)
ans = sum(a[:n])
print(ans)

-bc.sort(key=lambda x: x[1], reverse=True) -a.sort() +bc.sort(reverse=True, key=lambda x: x[1]) +li = [] +l = 0 -for b, c in bc: -    for _ in range(b): -        if i < n and a[i] < c: -            a[i] = c -            i += 1 -        else: -            break -ans = sum(a) +while i < m and l < n: +    b, c = bc[i] +    li += [c] * b +    i += 1 +    l += b +a += li +a.sort(reverse=True) +ans = sum(a[:n])