from itertools import groupby as gb

mai,sou=list(map(int,input().split()))

cards=[(e,len(list(f))) for e,f in gb(sorted(map(int,input().split())))]

sl=[tuple(list(map(int,input().split()))[::-1]) for a in range(sou)]

l=sorted(sl+cards,reverse=1)

s=0

for v,c in l:

  s+=v*min(mai,c)

  mai-=c

  if mai<=0:break

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

from collections import Counter as co

d=co(list(map(int,input().split())))

for i in range(m):

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

    if c in d:d[c]+=b

    else:d[c]=b

f=sorted(list(d.items()),reverse=1)



now =0

s=0

for k,v in f:

    if now+v<=n:

        now+=v

        s+=k*v

    else:

        

        print((s+(n-now)*k));exit()

from itertools import groupby as gb

mai, sou = list(map(int, input().split()))
cards = [(e, len(list(f))) for e, f in gb(sorted(map(int, input().split())))]
sl = [tuple(list(map(int, input().split()))[::-1]) for a in range(sou)]
l = sorted(sl + cards, reverse=1)
s = 0
for v, c in l:
    s += v * min(mai, c)
    mai -= c
    if mai <= 0:
        break
print(s)

n, m = list(map(int, input().split()))
from collections import Counter as co

d = co(list(map(int, input().split())))
for i in range(m):
    b, c = list(map(int, input().split()))
    if c in d:
        d[c] += b
    else:
        d[c] = b
f = sorted(list(d.items()), reverse=1)
now = 0
s = 0
for k, v in f:
    if now + v <= n:
        now += v
        s += k * v
    else:
        print((s + (n - now) * k))
        exit()

-from itertools import groupby as gb +n, m = list(map(int, input().split())) +from collections import Counter as co -mai, sou = list(map(int, input().split())) -cards = [(e, len(list(f))) for e, f in gb(sorted(map(int, input().split())))] -sl = [tuple(list(map(int, input().split()))[::-1]) for a in range(sou)] -l = sorted(sl + cards, reverse=1) +d = co(list(map(int, input().split()))) +for i in range(m): +    b, c = list(map(int, input().split())) +    if c in d: +        d[c] += b +    else: +        d[c] = b +f = sorted(list(d.items()), reverse=1) +now = 0 -for v, c in l: -    s += v * min(mai, c) -    mai -= c -    if mai <= 0: -        break -print(s) +for k, v in f: +    if now + v <= n: +        now += v +        s += k * v +    else: +        print((s + (n - now) * k)) +        exit()