n, m = gets.strip.split.map(&:to_i)
ab = []
n.times do
  a, b = gets.strip.split.map(&:to_i)
  next if a > m
  ab.unshift( [a, b] )
end

ab = ab.sort.reverse

#p ab
result = 0
(0...m).reverse_each do |day|
#p day
  work = ab.select {|work| work.first <= m-day }&.sort_by(&:last)&.last
  next if work.nil?

  result += work.last
  ab.delete(work)
end

p result
