def connect(a,b)
  list = []
  while !a.empty? && !b.empty?
    if a[0] > b[0]
      list.push(a[0])
      a.shift
    else
      list.push(b[0])
      b.shift
    end
  end
  if a.empty?
    list = list + b
  else
    list = list + a
  end
  list
end

n,m = gets.chomp.split(" ").map(&:to_i)

works = Array.new(10**5+1).map{Array.new}
n.times do |i|
  a,b = gets.chomp.split(" ").map(&:to_i)
  works[a].push(b)
end

ans = 0
list = []
for i in 1..m
  works[i].sort!.reverse!
  list = connect(list,works[i])
  if !list.empty?
    ans += list[0]
    list.shift
  end
end
puts ans