n, m = gets.split.map(&:to_i)
rewards =[]
n.times do
  rewards << gets.split.map(&:to_i)
end

rewards.sort! do |a, b|
  result = -(a[1] <=> b[1])
  if result == 0
    result = -(a[0] <=> b[0])
  end
  result
end

ans = 0
m.downto(1) do |i|
  break if rewards.empty?
  while rewards.size > 0
    reward = rewards[0]
    rewards.delete_at(0)
    if reward[0] <= i
      ans += reward[1]
      break
    end
  end
end

puts ans

