N, M = gets.split.map(&:to_i)
jobs_by_days = Array.new(100000) { Array.new }
N.times do
    a, b = gets.split.map(&:to_i)
    jobs_by_days[a] << b
end
jobs_by_days = jobs_by_days.map{|jobs| jobs.sort}
jobs_by_days[0] = [0]
jobs_to_take = []
current_days = 1
next_days = 2
while current_days <= M
    if jobs_by_days[current_days].empty?
        jobs_to_take << jobs_by_days[0..current_days-1].map{|ary| ary[-1]}.compact.max
        current_days += 1
        next_days = current_days + 1
        next
    end
    jobs_to_take << jobs_by_days[current_days].pop
    
    while (!jobs_by_days[current_days].empty? && !jobs_by_days[next_days].empty? && (job = jobs_by_days[current_days].pop) >= jobs_by_days[next_days][-1])
        jobs_to_take << job
        next_days += 1
    end
    current_days = next_days
    next_days = current_days + 1
end
puts jobs_to_take.inject(0, :+)