n, m = gets.chomp.split.map(&:to_i)
ab = []
n.times do |i|
  ab[i] = gets.chomp.split.map(&:to_i).reverse
end
ab.sort!.reverse!
i = 0
cnt = 0
#p ab
m.times do |j|
#  p [j, i, cnt]
  if i < n && ab[i][1] <= m - j
    cnt += ab[i][0]
    i += 1
  elsif i >= n
    break
  else
    i += 1
  end
end
#  p [i, cnt]
puts cnt
