output_description: Print the cost of the Ferris wheel for Takahashi.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      A B
attempt: def abc127d():
      N, M = (int(s) for s in input().split(" "))
      A = sorted(list(int(s) for s in input().split(" ")))
      for i in range(0, M):
          B, C = (int(s) for s in input().split(" "))
          r = len(list(filter(lambda x: x < C, A[:B])))
          A = sorted([C for n in range(0, r)] + A[r:])
      print(sum(A))
  
  
  abc127d()
  
problem_description: Statement
  
  Takahashi, who is A years old, is riding a Ferris wheel.
  
  It costs B yen (B is an even number) to ride the Ferris wheel if you are 13
  years old or older, but children between 6 and 12 years old (inclusive) can
  ride it for half the cost, and children who are 5 years old or younger are
  free of charge. (Yen is the currency of Japan.)
  
  Find the cost of the Ferris wheel for Takahashi.
samples: [{"input": "30 100", "output": "100\n    \n\nTakahashi is 30 years old now, and the cost of the Ferris wheel is 100 yen.\n\n* * *"}, {"input": "12 100", "output": "50\n    \n\nTakahashi is 12 years old, and the cost of the Ferris wheel is the half of 100\nyen, that is, 50 yen.\n\n* * *"}, {"input": "0 100", "output": "0\n    \n\nTakahashi is 0 years old, and he can ride the Ferris wheel for free."}]