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(out_cnt) do |a| b = (in_cnt + a) - out_cnt next if b < 0 if Q.all? { |x, y| x <= (out_cnt + b) - y } ans += 1 end end puts ans