n=int(input()) a,b=0,0 for i in range(n-1): q,w=map(int,input().split()) a+=q;b+=w if a