N = int(input()) AB = [list(map(int,input().split())) for i in range(N-1)] s = t = 0 for a,b in AB : s += a t += b if s < t : print(0) else : print(t+1)