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(s+1) else : print(t+1)