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

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

a.sort()



cards = []

for _ in range(m):

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

    cards.append([c, b])



cards.sort()

ans = 0

for i, num in enumerate(a):

    if not cards:

        break

    c, b = cards.pop()

    if c > num:

        a[i] = c

        b -= 1

    else:

        break



    if b:

        cards.append([c, b])



print((sum(a)))



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

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

a.sort(reverse=True)

x = []

for _ in range(m):

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

    x.append([b, c])



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



ret = 0

for b, c in x:

    if not a:

        break

    if c > a[-1]:

        while c > a[-1]:

            ret += c

            a.pop()

            b -= 1

            if b == 0:

                break

            if not a:

                break

    else:

        break



print((ret + sum(a)))



n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
cards = []
for _ in range(m):
    b, c = list(map(int, input().split()))
    cards.append([c, b])
cards.sort()
ans = 0
for i, num in enumerate(a):
    if not cards:
        break
    c, b = cards.pop()
    if c > num:
        a[i] = c
        b -= 1
    else:
        break
    if b:
        cards.append([c, b])
print((sum(a)))

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
x = []
for _ in range(m):
    b, c = list(map(int, input().split()))
    x.append([b, c])
x.sort(key=lambda p: p[1], reverse=True)
ret = 0
for b, c in x:
    if not a:
        break
    if c > a[-1]:
        while c > a[-1]:
            ret += c
            a.pop()
            b -= 1
            if b == 0:
                break
            if not a:
                break
    else:
        break
print((ret + sum(a)))

-a.sort() -cards = [] +a.sort(reverse=True) +x = [] -    cards.append([c, b]) -cards.sort() -ans = 0 -for i, num in enumerate(a): -    if not cards: +    x.append([b, c]) +x.sort(key=lambda p: p[1], reverse=True) +ret = 0 +for b, c in x: +    if not a: -    c, b = cards.pop() -    if c > num: -        a[i] = c -        b -= 1 +    if c > a[-1]: +        while c > a[-1]: +            ret += c +            a.pop() +            b -= 1 +            if b == 0: +                break +            if not a: +                break -    if b: -        cards.append([c, b]) -print((sum(a))) +print((ret + sum(a)))