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
n.times do |i|
    if ab[i][0] + day <= m then
        ans += ab[i][1]
        day += 1
        i -= 1
    end
end

puts ans