class Art
  attr_reader :size, :value
  def initialize(s, v)
    @size = s
    @value = v
  end
end

n = gets.to_i
arts = Array.new(n){
  a, b = gets.split(' ').map(&:to_i)
  Art.new(a, b)
}.sort_by{|a| a.size}
artSumValues = Array.new(n){|i|
  arts[i].value
}
for i in 1 ... n
  artSumValues[i] += artSumValues[i - 1]
end
min = -arts[0].size
max = artSumValues[0]
for i in 1 ... n
  if min > artSumValues[i - 1] - arts[i].size
    min = artSumValues[i - 1] - arts[i].size
  end
  if max < artSumValues[i] - arts[i].size - min
    max = artSumValues[i] - arts[i].size - min
  end
end
puts max
