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]] }

remain = M
worked = []

list.each do |d|
  break if remain == 0
  next if d[:d] > remain
  worked << d
  remain -= 1
end

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