from collections import deque def bfs(v): T=[-1]*(N+1) T[v]=0 Q=deque([v]) while Q: w=Q.popleft() for u in E[w]: if T[u]==-1: T[u]=T[w]+1 Q.append(u) x=max(range(1,N+1),key=lambda x:T[x]) return x,T[x] N=int(input()) E=[set() for _ in range(N+1)] for _ in range(N-1): a,b=map(int,input().split()) E[a].add(b) E[b].add(a) u,_=bfs(1) _,d=bfs(u) print((N-1)-d)