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

arr = Array.new(m, [])
n.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  next if a > m
  arr[a - 1] += [b]
end

answer = 0
m.times do |i|
  max = arr[i].max
  next unless max
  answer += max
  count = arr[i].count(max)
  break if i == m - 1
  arr[i + 1] += ((arr[i] - [max]) + ([max] * (count - 1)))
end
p answer
