import sys

f=lambda:list(map(int,sys.stdin.readline().split()))

n,m=f()

la=sorted(f())

ll=sorted([list(f()) for _ in range(m)],key=lambda k:-k[1])

ls=[]

t=a=0

for b,c in ll:

  if t+b>n: ls+=[c]*(n-t); t=n; break

  ls+=[c]*b; t+=b

for i in range(n):

  if i<t: a+=max(la[i],ls[i])

  else: a+=la[i]

print(a)
import sys

f=lambda:list(map(int,sys.stdin.readline().split()))

n,m=f();l=f();t=n

for b,c in sorted([f() for _ in range(m)],key=lambda k:-k[1]):

  l+=[c]*b;t+=b 

  if t>n*2:break

l.sort()

print((sum(l[-n:])))
import sys

f = lambda: list(map(int, sys.stdin.readline().split()))
n, m = f()
la = sorted(f())
ll = sorted([list(f()) for _ in range(m)], key=lambda k: -k[1])
ls = []
t = a = 0
for b, c in ll:
    if t + b > n:
        ls += [c] * (n - t)
        t = n
        break
    ls += [c] * b
    t += b
for i in range(n):
    if i < t:
        a += max(la[i], ls[i])
    else:
        a += la[i]
print(a)

import sys

f = lambda: list(map(int, sys.stdin.readline().split()))
n, m = f()
l = f()
t = n
for b, c in sorted([f() for _ in range(m)], key=lambda k: -k[1]):
    l += [c] * b
    t += b
    if t > n * 2:
        break
l.sort()
print((sum(l[-n:])))

-la = sorted(f()) -ll = sorted([list(f()) for _ in range(m)], key=lambda k: -k[1]) -ls = [] -t = a = 0 -for b, c in ll: -    if t + b > n: -        ls += [c] * (n - t) -        t = n +l = f() +t = n +for b, c in sorted([f() for _ in range(m)], key=lambda k: -k[1]): +    l += [c] * b +    t += b +    if t > n * 2: -    ls += [c] * b -    t += b -for i in range(n): -    if i < t: -        a += max(la[i], ls[i]) -    else: -        a += la[i] -print(a) +l.sort() +print((sum(l[-n:])))