N = gets.to_i Q = (N - 1).times.map { gets.split.map(&:to_i) } in_cnt = 0 out_cnt = 0 Q.each do |a, b| in_cnt += a out_cnt += b end ans = 0 0.upto(4_000_000) do |a| b = (a + in_cnt) - out_cnt next if b < 0 ans += 1 end puts ans