n, m = gets.split(' ').map(&:to_i)
arr = []
n.times do
  arr.push(gets.chomp.split(' ').map(&:to_i))
end
arr.sort_by! { |i| -i[1] - (0.1 * i[0]) }
value, current = 0, 0
arr.each do |i|
  if i[0] + current <= m
    value += i[1]
    current += 1
  end
end
puts value