from collections import defaultdict
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
bc=defaultdict(int)
for i in range(m):
  b,c=map(int,input().split())
  bc[c]+=b
i=0
newc=[0]*n
for c,b in sorted(bc.items(),key=lambda x:x[0],reverse=True):
  for _ in range(b):
    if i==n:
      break
    newc[i]=c
    i+=1
ans=sum(a)
for i in range(n):
  if newc[i]>a[i]:
    ans+=newc[i]-a[i]
print(ans) from collections import defaultdict n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a=[int(i) for i in input().split()] a [int(i) for i in input().split()] a.sort() a.sort a sort bc=defaultdict(int) bc defaultdict(int) defaultdict int for i in range(m):
  b,c=map(int,input().split())
  bc[c]+=b i range(m) range m b,c=map(int,input().split()) b map(int,input().split()) map int input().split() ().split () input split c bc[c]+=b bc[c] bc c b i=0 i 0 newc=[0]*n newc [0]*n [0] 0 n for c,b in sorted(bc.items(),key=lambda x:x[0],reverse=True):
  for _ in range(b):
    if i==n:
      break
    newc[i]=c
    i+=1 c b sorted(bc.items(),key=lambda x:x[0],reverse=True) sorted bc.items() bc.items bc items key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x reverse=True reverse True for _ in range(b):
    if i==n:
      break
    newc[i]=c
    i+=1 _ range(b) range b if i==n:
      break
     i==n i n break newc[i]=c newc[i] newc i c i+=1 i 1 ans=sum(a) ans sum(a) sum a for i in range(n):
  if newc[i]>a[i]:
    ans+=newc[i]-a[i] i range(n) range n if newc[i]>a[i]:
    ans+=newc[i]-a[i] newc[i]>a[i] newc[i] newc i a[i] a i ans+=newc[i]-a[i] ans newc[i]-a[i] newc[i] newc i a[i] a i print(ans) print ans a=[int(i) for i in input().split()] [int(i) for i in input().split()] a bc=defaultdict(int) defaultdict(int) bc c=map(int,input().split()) map(int,input().split()) c i+=1 1 i ans+=newc[i]-a[i] newc[i]-a[i] ans n,m=map(int,input().split()) map(int,input().split()) n i=0 0 i newc=[0]*n [0]*n newc m=map(int,input().split()) map(int,input().split()) m ans=sum(a) sum(a) ans b,c=map(int,input().split()) map(int,input().split()) b
from collections import defaultdict
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
bc=defaultdict(int)
for i in range(m):
  b,c=map(int,input().split())
  bc[c]+=b
i=0
newc=[0]*n
for c,b in sorted(bc.items(),key=lambda x:x[0],reverse=True):
  for _ in range(b):
    if i==n:
      break
    newc[i]=c
    i+=1
ans=sum(a)
for i in range(n):
  if newc[i]>a[i]:
    ans+=newc[i]-a[i]
print(ans)