N, M = gets.split.map(&:to_i)
AB = []
N.times do
  line = gets.split.map(&:to_i)
  AB << line
end
AB.sort!
CD = []
ans = 0

(1..M).each do |n|
  while AB[0] && AB[0][0] == n
    if CD[0]
      ind = 0
      while CD[ind] && CD[ind] > AB[0][1]
        ind += 1
      end
      CD.insert(ind, AB[0][1])
    else
      CD.push(AB[0][1])
    end
    AB.delete_at(0)
  end
  
  if CD[0]
    ans += CD[0]
    CD.delete_at(0)
  end
end
  
print ans