n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
l = []
okikae = []

for i in range(m):
  b,c = map(int,input().split())
  l.append([c,b])
  
l.sort(reverse = True)

for c,b in l:
  for j in range(b):
    if len(okikae) < len(a):
      okikae.append(c)
    else:
      break
  if len(okikae) == len(a):
    break
    
    
for i in range(len(okikae)):
  if okikae[i] > a[i]:
    a[i] = okikae[i]
  else:
    break
    
print(sum(a)) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a = list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a.sort() a.sort a sort l = [] l [] okikae = [] okikae [] for i in range(m):
  b,c = map(int,input().split())
  l.append([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 l.append([c,b]) l.append l append [c,b] c b l.sort(reverse = True) l.sort l sort reverse = True reverse True for c,b in l:
  for j in range(b):
    if len(okikae) < len(a):
      okikae.append(c)
    else:
      break
  if len(okikae) == len(a):
    break
    
     c b l for j in range(b):
    if len(okikae) < len(a):
      okikae.append(c)
    else:
      break
   j range(b) range b if len(okikae) < len(a):
      okikae.append(c)
    else:
      break
   len(okikae) < len(a) len(okikae) len okikae len(a) len a okikae.append(c) okikae.append okikae append c break if len(okikae) == len(a):
    break
    
     len(okikae) == len(a) len(okikae) len okikae len(a) len a break for i in range(len(okikae)):
  if okikae[i] > a[i]:
    a[i] = okikae[i]
  else:
    break
     i range(len(okikae)) range len(okikae) len okikae if okikae[i] > a[i]:
    a[i] = okikae[i]
  else:
    break
     okikae[i] > a[i] okikae[i] okikae i a[i] a i a[i] = okikae[i] a[i] a i okikae[i] okikae i break print(sum(a)) print sum(a) sum a m = map(int,input().split()) map(int,input().split()) m c = map(int,input().split()) map(int,input().split()) c okikae = [] [] okikae n,m = map(int,input().split()) map(int,input().split()) n b,c = map(int,input().split()) map(int,input().split()) b a = list(map(int,input().split())) list(map(int,input().split())) a l = [] [] l
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
l = []
okikae = []

for i in range(m):
  b,c = map(int,input().split())
  l.append([c,b])
  
l.sort(reverse = True)

for c,b in l:
  for j in range(b):
    if len(okikae) < len(a):
      okikae.append(c)
    else:
      break
  if len(okikae) == len(a):
    break
    
    
for i in range(len(okikae)):
  if okikae[i] > a[i]:
    a[i] = okikae[i]
  else:
    break
    
print(sum(a))