import copy N = int(input()) A = [] B = [] AB = [] for i in range(N-1): a,b = map(int,input().split()) A.append(a) B.append(b) AB.append([a,b]) ma = max(sum(A),sum(B)) AB = sorted(AB, key=lambda x:(x[1]), reverse=True) A = [] B = [] for i in range(N-1): A.append(AB[i][0]) B.append(AB[i][1]) amarib = 0 D = copy.deepcopy(A) for i in range(len(A)): b = B[i] for j in reversed(range(len(A))): if i==j: continue temp = min(D[j],b) b-=temp D[j]-=temp amarib += b AB = sorted(AB, key=lambda x:(x[0]), reverse=True) A = [] B = [] for i in range(N-1): A.append(AB[i][0]) B.append(AB[i][1]) amaria = 0 D = copy.deepcopy(B) for i in range(len(A)): a = A[i] for j in reversed(range(len(A))): if i==j: continue temp = min(D[j],a) a-=temp D[j]-=temp amaria += a print(ma-max(amaria,amarib)+1)