N, M = gets.split(' ').map(&:to_i)
works = Array.new
N.times do |i|
	a, b = gets.split(' ').map(&:to_i)
	works.push([a, b])
end
works.sort_by!{|w| -w[1]}

ans = 0
wl = []
cnt = 0
works.each do |x, y|
	if wl.count{|n| n >= x} < M - x
		ans += y
		wl.push(x)
		cnt += 1
	end
	break if cnt == M
end
puts ans