n,m  = gets.chomp.split.collect{ |item| item.to_i}
list = []
(m+2).times do |i|
  list[i] = [0]
end

n.times do |ni|
  aa,bb = gets.chomp.split.collect{ |item| item.to_i}
  list[aa].each_with_index do |bi,idx|
    if bb >= bi
      list[aa].insert(idx,bb)
      break
    end
  end
end
def jointlist(lista,listb,max)
  result = []
  max.times do |i|
    if lista[0] >= listb[0]
      result.push(lista.shift)
      lista.push(0)
    else
      result.push(listb.shift)
      listb.push(0)
    end
  end
  return result
end
result = 0
canlist = [0]
1.upto(m) do |day|
  canlist = jointlist(canlist,list[day],m-day+1)
money = canlist.shift
result += money
end
puts result
