N, M = gets.split.map(&:to_i)

list = []

N.times do
  d = gets.split.map(&:to_i)
  list << { d: d[0], r: d[1] } unless d[0] > M
end

list.sort_by! { |d| [-d[:r], -d[:d]] }

days = 1
worked = []

while true
  idx = nil
  list.each_with_index do |d, i|
    next if d[:d] > days
    idx = i
    break
  end

  worked << list.delete_at(idx) if idx
  days += 1

  break if days > M
end

p worked.map { |d| d[:r] }.inject(:+) || 0
