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

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

l=[list(map(int,input().split()))[::-1] for _ in range(m)]

a.sort()

d=[]

e=0

for c,b in sorted(l)[::-1]:

	d+=[c]*b

	e+=b

	if e>n:break

for i,(x,y) in enumerate(zip(a,d)):

	if x<y:a[i]=y

print((sum(a)))

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

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

Z=[list(map(int,input().split()))[::-1] for _ in range(m)]

d=[]

e=0

a.sort()

Z.sort(reverse=True)

for c,b in Z:

    d+=[c]*b

    e+=b

    if e>n:

        break



for i , (x,y) in enumerate(zip(a,d)):

    if x<y:

        a[i]=y



print((sum(a)))

n, m = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
l = [list(map(int, input().split()))[::-1] for _ in range(m)]
a.sort()
d = []
e = 0
for c, b in sorted(l)[::-1]:
    d += [c] * b
    e += b
    if e > n:
        break
for i, (x, y) in enumerate(zip(a, d)):
    if x < y:
        a[i] = y
print((sum(a)))

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
Z = [list(map(int, input().split()))[::-1] for _ in range(m)]
d = []
e = 0
a.sort()
Z.sort(reverse=True)
for c, b in Z:
    d += [c] * b
    e += b
    if e > n:
        break
for i, (x, y) in enumerate(zip(a, d)):
    if x < y:
        a[i] = y
print((sum(a)))

-(*a,) = list(map(int, input().split())) -l = [list(map(int, input().split()))[::-1] for _ in range(m)] -a.sort() +a = list(map(int, input().split())) +Z = [list(map(int, input().split()))[::-1] for _ in range(m)] -for c, b in sorted(l)[::-1]: +a.sort() +Z.sort(reverse=True) +for c, b in Z: