import numpy as np from scipy.sparse.csgraph import maximum_flow from scipy.sparse import csr_matrix from itertools import product def solve(ab): INF = 10**9 ab = [(INF,INF)]+ab n = len(ab) g = np.zeros((2*n+2,2*n+2), dtype=int) # 0: start, 1: goal, 2-(n+1): left, (n+2)-(2n-1): right for i,(a,b) in enumerate(ab): g[0,i+2] = a g[i+n+2,1] = b for i,j in product(range(n), repeat=2): if i == j: continue g[i+2,j+n+2] = INF t = maximum_flow(csr_matrix(g), 0, 1).flow_value ta = sum(a for a,b in ab[1:]) tb = sum(b for a,b in ab[1:]) return t-max(ta,tb)+1 n = int(input()) ab = [tuple(map(int,input().split())) for _ in range(n-1)] print(solve(ab))