n,m = gets.split.map(&:to_i)
ba = []
readlines.map do |i|
  temp = i.chomp.split.map(&:to_i)
  ba << [temp[1], temp[0]]
end
#puts ba.to_s

sorted = ba.sort{|a,b| b <=> a}

#d
#puts sorted.to_s

sum = 0
checked = 0
1.upto(m) do |day|
  checked.upto(n-1).each do |cc|
    if m-day+1 >= sorted[cc][1]
      sum += sorted[cc][0]
      checked = cc + 1
      #puts sum
      break
    end
  end
end

puts sum