n,m=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
a.sort(reverse=True)
d=[]
bc=[]
for i in range(m):
  b,c=[int(x) for x in input().rstrip().split()]
  bc.append([b,c])

cnt=0
bc.sort(key=lambda x:x[1],reverse=True)
for b,c in bc:

  d.extend([c]*b)
  cnt+=b
  if n<cnt:
    break
  
d.sort(reverse=True)
a+=d
a.sort(reverse=True)
print(sum(a[:n])) int(x) for x in input().rstrip().split() for x in input().rstrip().split() x input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split for x in input().rstrip().split() int(x) int x n,m=[int(x) for x in input().rstrip().split()] n [int(x) for x in input().rstrip().split()] m int(x) for x in input().rstrip().split() for x in input().rstrip().split() x input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split for x in input().rstrip().split() int(x) int x a=[int(x) for x in input().rstrip().split()] a [int(x) for x in input().rstrip().split()] a.sort(reverse=True) a.sort a sort reverse=True reverse True d=[] d [] bc=[] bc [] for i in range(m):
  b,c=[int(x) for x in input().rstrip().split()]
  bc.append([b,c]) i range(m) range m int(x) for x in input().rstrip().split() for x in input().rstrip().split() x input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split for x in input().rstrip().split() int(x) int x b,c=[int(x) for x in input().rstrip().split()] b [int(x) for x in input().rstrip().split()] c bc.append([b,c]) bc.append bc append [b,c] b c cnt=0 cnt 0 bc.sort(key=lambda x:x[1],reverse=True) bc.sort bc sort key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse=True reverse True for b,c in bc:

  d.extend([c]*b)
  cnt+=b
  if n<cnt:
    break
   b c bc d.extend([c]*b) d.extend d extend [c]*b [c] c b cnt+=b cnt b if n<cnt:
    break
   n<cnt n cnt break d.sort(reverse=True) d.sort d sort reverse=True reverse True a+=d a d a.sort(reverse=True) a.sort a sort reverse=True reverse True print(sum(a[:n])) print sum(a[:n]) sum a[:n] a :n n m=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] m cnt+=b b cnt c=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] c a=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] a bc=[] [] bc b,c=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] b cnt=0 0 cnt d=[] [] d a+=d d a n,m=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] n
n,m=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
a.sort(reverse=True)
d=[]
bc=[]
for i in range(m):
  b,c=[int(x) for x in input().rstrip().split()]
  bc.append([b,c])

cnt=0
bc.sort(key=lambda x:x[1],reverse=True)
for b,c in bc:

  d.extend([c]*b)
  cnt+=b
  if n<cnt:
    break
  
d.sort(reverse=True)
a+=d
a.sort(reverse=True)
print(sum(a[:n]))
