n,m  = gets.chomp.split.collect{ |item| item.to_i}
list = []
(m+2).times do |i|
  list[i] = [0]
end

n.times do |ni|
  aa,bb = gets.chomp.split.collect{ |item| item.to_i}
  next if aa > m
  list[aa].each_with_index do |bi,idx|
    if bb >= bi
      list[aa].insert(idx,bb)
      break
    end
  end
end

result = 0
canlist = [0]
1.upto(m) do |day|
  arr = list[1..day].collect{|a| a[0] == nil ? 0:a[0]}
  max = arr.max
  maxi = arr.rindex(max)
  a = list[maxi+1].shift
  result += max
end
puts result
