output_description: Print the maximum possible sum of the integers written on the N cards after
  the M operations.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      A_1 A_2 ... A_N
      B_1 C_1
      B_2 C_2
      \vdots
      B_M C_M
attempt: # -*- coding: utf-8 -*-
  
  import sys
  
  input = sys.stdin.readline
  
  
  def io_generator():
      return input()
  
  
  def iil(a_io):
      return map(int, a_io().split())
  
  
  # +++++++++++++++++++
  
  
  def main(io):
      n, m = iil(io)
      aas = list(iil(io))
      bbs = []
      for _ in range(m):
          b, c = iil(io)
          bbs.append((b, c))
  
      aas.sort()
      # print(aas)
      bbs = sorted(bbs, key=lambda t: -t[1])
      # print(bbs)
      bbii = 0
      bbij = 0
      ret = 0
      ddd = 0
      for i in aas:
          if ddd == 1:
              ret += i
              continue
  
          if i > bbs[bbii][1]:
              ret += i
              ddd = 1
              continue
  
          ret += bbs[bbii][1]
  
          bbij += 1
          if bbij >= bbs[bbii][0]:
              bbij = 0
              bbii += 1
  
          if bbii >= len(bbs):
              ddd = 1
      return ret
  
      return
  
  
  # ++++++++++++++++++++
  
  if __name__ == "__main__":
      io = lambda: io_generator()
      ret = main(io)
      if ret is not None:
          print(ret)
  
problem_description: Statement
  
  You have N cards. On the i-th card, an integer A_i is written.
  
  For each j = 1, 2, ..., M in this order, you will perform the following
  operation once:
  
  Operation: Choose at most B_j cards (possibly zero). Replace the integer
  written on each chosen card with C_j.
  
  Find the maximum possible sum of the integers written on the N cards after the
  M operations.
samples: [{"input": "3 2\n    5 1 4\n    2 3\n    1 5", "output": "14\n    \n\nBy replacing the integer on the second card with 5, the sum of the integers\nwritten on the three cards becomes 5 + 5 + 4 = 14, which is the maximum\nresult.\n\n* * *"}, {"input": "10 3\n    1 8 5 7 100 4 52 33 13 5\n    3 10\n    4 30\n    1 4", "output": "338\n    \n\n* * *"}, {"input": "3 2\n    100 100 100\n    3 99\n    3 99", "output": "300\n    \n\n* * *"}, {"input": "11 3\n    1 1 1 1 1 1 1 1 1 1 1\n    3 1000000000\n    4 1000000000\n    3 1000000000", "output": "10000000001\n    \n\nThe output may not fit into a 32-bit integer type."}]