n = int(input()) G = [[] for _ in range(n)] for _ in range(n - 1): a,b = map(int,input().split()) a -= 1 b -= 1 G[a].append(b) G[b].append(a) def max_depth(s): ans = 0 idx = 0 depth = [-1] * n depth[s] = 0 stack = [s] while stack: p = stack.pop() for v in G[p]: if depth[v] >= 0: continue depth[v] = depth[p] + 1 if ans < depth[v]: ans = depth[v] idx = v stack.append(v) return ans,idx depth,s = max_depth(0) max_dep,i = max_depth(s) print(n - max_dep - 1)