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

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

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

l=sorted(l,key=lambda x:x[1], reverse=True)



p=0

comp=[]

for b,c in l:

  comp+=[c]*b

  p+=b

  if p>=n:

    break



ans=0

for i in range(n):

  if i<len(comp):

    ans+=max(a[i],comp[i])

  else:

    ans+=a[i]

print(ans)
from sys import stdin

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



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

a=sorted(list(na()))

l=[list(na()) for i in range(m)]

l=sorted(l,key=lambda x:x[1], reverse=True)



p=0

comp=[]

for b,c in l:

  comp+=[c]*b

  p+=b

  if p>=n:

    break



ans=0

for i in range(n):

  if i<len(comp):

    ans+=max(a[i],comp[i])

  else:

    ans+=a[i]

print(ans)
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
l = [list(map(int, input().split())) for i in range(m)]
l = sorted(l, key=lambda x: x[1], reverse=True)
p = 0
comp = []
for b, c in l:
    comp += [c] * b
    p += b
    if p >= n:
        break
ans = 0
for i in range(n):
    if i < len(comp):
        ans += max(a[i], comp[i])
    else:
        ans += a[i]
print(ans)

from sys import stdin

na = lambda: list(map(int, stdin.readline().split()))
n, m = list(map(int, input().split()))
a = sorted(list(na()))
l = [list(na()) for i in range(m)]
l = sorted(l, key=lambda x: x[1], reverse=True)
p = 0
comp = []
for b, c in l:
    comp += [c] * b
    p += b
    if p >= n:
        break
ans = 0
for i in range(n):
    if i < len(comp):
        ans += max(a[i], comp[i])
    else:
        ans += a[i]
print(ans)

+from sys import stdin + +na = lambda: list(map(int, stdin.readline().split())) -a = sorted(list(map(int, input().split()))) -l = [list(map(int, input().split())) for i in range(m)] +a = sorted(list(na())) +l = [list(na()) for i in range(m)]