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

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

a.sort()



card=[]



for i in range(M):

    b, c=list(map(int, input().split()))

    card.append((c, b))



card.sort(reverse=True)

k=0

for c, b in card:

    while k < N and b > 0:

        if a[k]<c:

            a[k]=c

            b-=1

        k+=1



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

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

a.sort()

change=[]



for i in range(m):

    b, c=list(map(int, input().split()))

    change.append((c, b))



change.sort(reverse=True)

elem=0



for c, b in change:

    while elem<n and b>0:

        if a[elem]<c:

            a[elem]=c

            b-=1

        elem+=1



print((sum(a)))
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
card = []
for i in range(M):
    b, c = list(map(int, input().split()))
    card.append((c, b))
card.sort(reverse=True)
k = 0
for c, b in card:
    while k < N and b > 0:
        if a[k] < c:
            a[k] = c
            b -= 1
        k += 1
print((sum(a)))

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
change = []
for i in range(m):
    b, c = list(map(int, input().split()))
    change.append((c, b))
change.sort(reverse=True)
elem = 0
for c, b in change:
    while elem < n and b > 0:
        if a[elem] < c:
            a[elem] = c
            b -= 1
        elem += 1
print((sum(a)))

-N, M = list(map(int, input().split())) +n, m = list(map(int, input().split())) -card = [] -for i in range(M): +change = [] +for i in range(m): -    card.append((c, b)) -card.sort(reverse=True) -k = 0 -for c, b in card: -    while k < N and b > 0: -        if a[k] < c: -            a[k] = c +    change.append((c, b)) +change.sort(reverse=True) +elem = 0 +for c, b in change: +    while elem < n and b > 0: +        if a[elem] < c: +            a[elem] = c -        k += 1 +        elem += 1