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: N, M = map(int, input().split())
  listA = list(map(int, input().strip().split()))
  
  
  class BCSet:
      B = 0
      C = 0
  
  
  listBC = []
  
  for i in range(0, M):
      B, C = map(int, input().split())
      new_BCSet = BCSet()
      new_BCSet.B = B
      new_BCSet.C = C
      listBC.append(new_BCSet)
  
  
  def MurgeSort(left, right):
      if right - left == 1:
          return
      mid = left + int((right - left) / 2)
      MurgeSort(left, mid)
      MurgeSort(mid, right)
      tmp = []
      for i in range(left, mid):
          tmp.append(listBC[i])
      for i in range(mid, right):
          tmp.append(listBC[mid + right - i - 1])
      iterator_left = 0
      iterator_right = right - left - 1
      for i in range(left, right):
          if tmp[iterator_left].C <= tmp[iterator_right].C:
              listBC[i] = tmp[iterator_left]
              iterator_left += 1
          else:
              listBC[i] = tmp[iterator_right]
              iterator_right -= 1
  
  
  def AMurgeSort(left, right):
      if right - left == 1:
          return
      mid = left + int((right - left) / 2)
      AMurgeSort(left, mid)
      AMurgeSort(mid, right)
      tmp = []
      for i in range(left, mid):
          tmp.append(listA[i])
      for i in range(mid, right):
          tmp.append(listA[mid + right - i - 1])
      iterator_left = 0
      iterator_right = right - left - 1
      for i in range(left, right):
          if tmp[iterator_left] <= tmp[iterator_right]:
              listA[i] = tmp[iterator_left]
              iterator_left += 1
          else:
              listA[i] = tmp[iterator_right]
              iterator_right -= 1
  
  
  MurgeSort(0, M)
  AMurgeSort(0, N)
  
  sum = 0
  card_total = 0
  cpoint = 0
  iadjuster = 0
  
  for i in range(0, N):
      if listA[N - i - 1 + iadjuster] >= listBC[M - cpoint - 1].C or cpoint >= M:
          card_total += 1
          sum += listA[N - i - 1 + iadjuster]
          if card_total == N:
              break
      else:
          if card_total + listBC[M - cpoint - 1].B > N:
              sum += (
                  listBC[M - cpoint - 1].B - (card_total + listBC[M - cpoint - 1].B - N)
              ) * listBC[M - cpoint - 1].C
              break
          else:
              card_total += listBC[M - cpoint - 1].B
              sum += listBC[M - cpoint - 1].B * listBC[M - cpoint - 1].C
              cpoint += 1
              iadjuster += 1
  
  
  print("{}".format(sum))
  
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."}]