n, m = gets.split.map(&:to_i)
abs = []
n.times do |i|
  abs << gets.split.map(&:to_i)
end

abs.sort_by! { |a, b| [-b, -a] }

# puts abs.inspect

ans = 0

c = 0
d = 0
while d <= m && c <= n-1 do
  ab = abs[c]
  a = ab[0]
  b = ab[1]

  if a + d <= m
    ans += b
    d += 1
  end
  c += 1

  # abs.each_with_index do |ab, i|
  #   a = ab[0]
  #   b = ab[1]

  #   if a + i <= m
  #     ans += b
  #   end
  # end
end

puts ans