N, M = gets.split(' ').map(&:to_i)
works = Array.new(M + 1){Array.new}
N.times do |i|
	a, b = gets.split(' ').map(&:to_i)
	works[a].push(b)
end
1.upto(M) do |i|
	if !works[i].empty?
		works[i] = works[i].sort.reverse
	end
end

ans = 0
wl = []
1.upto(M) do |i|
	wl += works[i]
	if !wl.empty?
		n = wl.max
		ans += n
		t = wl.index(n)
		wl.delete_at(t)
	end
end

puts ans