N, M = gets.split.map(&:to_i)
AB = []
N.times do
  line = gets.split.map(&:to_i)
  AB << line
end
AB.sort!
CD = []
ans = 0

(1..M).each do |n|
  while AB[0] && AB[0][0] == n
    CD.push(AB[0][1])
    AB.delete_at(0)
  end
  CD.sort!.reverse!
  if CD[0]
    ans += CD[0]
    CD.delete_at(0)
  end
end
  
print ans