N, M = gets.split.map(&:to_i)
Job = Struct.new(:day, :money) do
  def <=>(other)
    n = other.money <=> money
    n == 0 ? day <=> other.day : n
  end
end
jobs = $<.read.split(?\n).map {|x| Job.new(*x.split.map(&:to_i))}.sort!

days = [*1..M]
sum_money = jobs.reduce(0) do |sum, job|
  next(sum) unless i = days.bsearch_index {|day| day >= job.day}
  days.delete_at(i)
  sum + job.money
end

puts sum_money
