n, m = gets.split.map!(&:to_i)
ab = n.times.map{gets.split.map(&:to_i)}
ab.sort!{|x,y| -x[0] <=> -y[0]}.sort!{|x,y| -x[1] <=> -y[1]}

ans = 0
day = 0
ab.each do |x|
    if x[0] + day <= m then
        ans += x[1]
        day += 1
    end
end

puts ans