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

list = Array.new(10**5 + 1){[]}
n.times do
  a, b = gets.split.map(&:to_i)
  list[a] << b
end

count = 0
m.times do |i|
  next if list[i + 1] == []
  list[i + 1].sort!
  count += list[i + 1][-1]
  list[i + 2] += list[i + 1][0..-2]
end

puts count