n,m = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]

a.sort()



cb = []

for _ in range(m):

    b, c = [int(i) for i in input().split()]

    cb.append([c, b])

cb.sort(reverse=1)



i = 0

j = 0

for k in range(n):

    a[k] = max(a[k], cb[i][0])

    j += 1

    if j == cb[i][1]:

        i += 1

        j = 0

    if i == m:

        break

print((sum(a)))
n, m = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]

a.sort()

bc = [[int(i) for i in input().split()] for _ in range(m)]

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



i = 0

for b, c in bc:

    for _ in range(b):

        a[i] = max(a[i], c)

        i += 1

        if i == n:

            break

    if i == n:

        break

print((sum(a)))
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
cb = []
for _ in range(m):
    b, c = [int(i) for i in input().split()]
    cb.append([c, b])
cb.sort(reverse=1)
i = 0
j = 0
for k in range(n):
    a[k] = max(a[k], cb[i][0])
    j += 1
    if j == cb[i][1]:
        i += 1
        j = 0
    if i == m:
        break
print((sum(a)))

n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
bc = [[int(i) for i in input().split()] for _ in range(m)]
bc.sort(key=lambda x: -x[1])
i = 0
for b, c in bc:
    for _ in range(b):
        a[i] = max(a[i], c)
        i += 1
        if i == n:
            break
    if i == n:
        break
print((sum(a)))

-cb = [] -for _ in range(m): -    b, c = [int(i) for i in input().split()] -    cb.append([c, b]) -cb.sort(reverse=1) +bc = [[int(i) for i in input().split()] for _ in range(m)] +bc.sort(key=lambda x: -x[1]) -j = 0 -for k in range(n): -    a[k] = max(a[k], cb[i][0]) -    j += 1 -    if j == cb[i][1]: +for b, c in bc: +    for _ in range(b): +        a[i] = max(a[i], c) -        j = 0 -    if i == m: +        if i == n: +            break +    if i == n: