n, m = gets().split(' ').map(&:to_i)

anbn = []
n.times {|i|
	ai, bi = gets().split(' ').map(&:to_i)
	next if ai > m
	anbn.push([ai, bi])
}

anbn.sort!{|x, y|
	x[0] == y[0] ? (y[1] <=> x[1]) : (x[0] <=> y[0])
}

works = [nil]
anbn.each{|x|
	ai = x[0]
	bi = x[1]

	for i in ai .. m
		if works.length <= i
			works[i] = bi
			break
		elsif works[i] == nil
			works[i] = bi
			break
		elsif works[i] < bi
			temp = works[i]
			works[i] = bi
			bi = temp
		end
	end
}

sum = 0
works[1 .. m].each {|x|
	sum += x if x != nil
}

puts sum
