from collections import deque def bfs(x): dis = [n]*(n) dis[x] = 0 q = deque([x]) while q: now = q.popleft() for nex in e[now]: if dis[nex] > dis[now]+1: dis[nex] = dis[now]+1 q.append(nex) return dis def Euler_Tour(x): vis = [0]*n stack = [~x,x] ans = [0]*n vis[x] = 1 count = -1 while stack: now = stack.pop() count += 1 if now >= 0: ans[now] = count for nex in e[now]: if dis[nex] == dis[now]-1 and vis[nex] == 0: vis[nex] = 1 stack.append(~nex) stack.append(nex) for nex in e[now]: if vis[nex] == 0: vis[nex] = 1 stack.append(~nex) stack.append(nex) return ans n = int(input()) e = [[] for i in range(n)] for i in range(n-1): a,b = map(int,input().split()) a -= 1 b -= 1 e[a].append(b) e[b].append(a) dis = bfs(0) dis = bfs(dis.index(max(dis))) print(max(Euler_Tour(dis.index(max(dis)))))