N, M = gets.strip.split(' ').map(&:to_i)
ABS = readlines.map {|line| line.split(' ').map(&:to_i)}

money = 0
left_day = M

ABS.sort_by! {|x| [-x[1], -x[0]]}

M.times do |i|
  ABS.delete_if{|job| job[0] > left_day}
  break if ABS.select{|job| job[0] <= left_day}.size == 0
  ABS.size.times do |index|
    if ABS[index][0] <= left_day
      money += ABS[index][1]
      left_day -= 1
      ABS.delete_at(index)
      break
    end
  end
end

puts money