output_description: Print the maximum total reward that you can earn no later than M days from
  today.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      A_1 B_1
      A_2 B_2
      \vdots
      A_N B_N
attempt: N, M = map(int, input().split())
  A, B = zip(*(map(int, input().split()) for _ in range(N))) if N else ((), ())
  
  
  class SegmentTree:
      def __init__(self, n, f, e):
          self.n = 2 ** ((n - 1).bit_length())
          self.f = f
          self.e = e
          self.d = [e for _ in range(2 * self.n)]
  
      def __setitem__(self, key, value):
          key += self.n - 1
          self.d[key] = value
          while key > 1:
              key //= 2
              self.d[key] = self.f(self.d[2 * key], self.d[2 * key + 1])
  
      def __getitem__(self, key):
          return self.q(key, 1, 1, self.n + 1)
  
      def q(self, key, i, left, right):
          return (
              self.e
              if left >= key.stop or right <= key.start
              else (
                  self.d[i]
                  if key.start <= left <= right <= key.stop
                  else self.f(
                      self.q(key, 2 * i, left, (left + right) // 2),
                      self.q(key, 2 * i + 1, (left + right) // 2, right),
                  )
              )
          )
  
  
  T = SegmentTree(M, max, -1)
  for i in range(M + 1):
      T[i] = i
  
  ans = 0
  for a, b in sorted(zip(A, B), key=lambda t: (-t[1], t[0])):
      x = T[1 : (M - a + 2)]
      if x != -1:
          ans += b
          T[x] = -1
  
  print(ans)
  
problem_description: Statement
  
  There are N one-off jobs available. If you take the i-th job and complete it,
  you will earn the reward of B_i after A_i days from the day you do it.
  
  You can take and complete at most one of these jobs in a day.
  
  However, you cannot retake a job that you have already done.
  
  Find the maximum total reward that you can earn no later than M days from
  today.
  
  You can already start working today.
samples: [{"input": "3 4\n    4 3\n    4 1\n    2 2", "output": "5\n    \n\nYou can earn the total reward of 5 by taking the jobs as follows:\n\n  * Take and complete the first job today. You will earn the reward of 3 after four days from today.\n  * Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.\n\n* * *"}, {"input": "5 3\n    1 2\n    1 3\n    1 4\n    2 1\n    2 3", "output": "10\n    \n\n* * *"}, {"input": "1 1\n    2 1", "output": "0"}]