N, M = gets.chomp.split.map &:to_i

WORKS = N.times.map do |i|
  a, b = gets.chomp.split.map &:to_i
  [a, b, i]
end

money = 0
1.upto(M) do |d|
  max_income = 0
  index = nil
  WORKS.each_with_index do |w, i|
    # p [d, w]
    next if d < w[0]
    next if max_income > w[1]
    index = i
    max_income = w[1]
  end
  next if index.nil?
  # p index

  money += WORKS[index][1]
  WORKS.delete_at(index)
end

p money
