from collections import Counter



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

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

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

b = {}

ans = 0



for i, j in bc:

    if j in b:

        ref = b[j]

        b[j] = ref + i

    else:

        b[j] = i



d = Counter(a) + Counter(b)

keys = sorted(d)[::-1]



for key in keys:

    qty = d[key]

    if qty < n:

        ans += qty*key

        n -= qty

    else:

        ans += n*key

        break



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

l = [(a, 1) for a in list(map(int, input().split()))]

for i in range(m):

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

    l.append((c, b))

l = sorted(l)[::-1]

ans = 0



for i, j in l:

    if j < n:

        ans += i*j

        n -= j

    else:

        ans += n*i

        break



print(ans)
from collections import Counter

n, m = list(map(int, input().split()))
a = Counter(list(map(int, input().split())))
bc = [list(map(int, input().split())) for i in range(m)]
b = {}
ans = 0
for i, j in bc:
    if j in b:
        ref = b[j]
        b[j] = ref + i
    else:
        b[j] = i
d = Counter(a) + Counter(b)
keys = sorted(d)[::-1]
for key in keys:
    qty = d[key]
    if qty < n:
        ans += qty * key
        n -= qty
    else:
        ans += n * key
        break
print(ans)

n, m = list(map(int, input().split()))
l = [(a, 1) for a in list(map(int, input().split()))]
for i in range(m):
    b, c = list(map(int, input().split()))
    l.append((c, b))
l = sorted(l)[::-1]
ans = 0
for i, j in l:
    if j < n:
        ans += i * j
        n -= j
    else:
        ans += n * i
        break
print(ans)

-from collections import Counter - -a = Counter(list(map(int, input().split()))) -bc = [list(map(int, input().split())) for i in range(m)] -b = {} +l = [(a, 1) for a in list(map(int, input().split()))] +for i in range(m): +    b, c = list(map(int, input().split())) +    l.append((c, b)) +l = sorted(l)[::-1] -for i, j in bc: -    if j in b: -        ref = b[j] -        b[j] = ref + i +for i, j in l: +    if j < n: +        ans += i * j +        n -= j -        b[j] = i -d = Counter(a) + Counter(b) -keys = sorted(d)[::-1] -for key in keys: -    qty = d[key] -    if qty < n: -        ans += qty * key -        n -= qty -    else: -        ans += n * key +        ans += n * i