num = gets
car_m = gets
sum = car_m.to_i
sum_ar = Array.new
num.to_i.times do |index|
	car_i = gets.split(nil)
	sum = sum + car_i[0].to_i - car_i[1].to_i
	if sum < 0
		puts "0"
		break
	end
	sum_ar[index] = sum
end
if sum >= 0
	sorted = sum_ar.sort
	puts sorted[-1]
end