n,m  = gets.chomp.split.collect{ |item| item.to_i}
list = []
(m+2).times do |i|
  list[i] = [0]
end
n.times do |ni|
  aa,bb = gets.chomp.split.collect{ |item| item.to_i}
  list[aa].push(bb)#({:day => aa,:kane => bb})
end
result = 0
canlist = []
1.upto(m) do |day|
  canlist += list[day]
   money = canlist.max
  result += money
  idx = canlist.index(money)
  canlist.delete_at(idx)
end
puts result
