n = int(input()) g = [[] for _ in range(n)] p = [0]*n for _ in range(n-1): u, v = map(int, input().split()) g[u-1].append(v-1) g[v-1].append(u-1) p[v-1] = u-1 a = [] s = [(0,0)] while s: i,p = s.pop() a.append((i,p)) s.extend((j,i) for j in g[i] if j!=p) dp = [[0]*n, [0]*n] for j in range(n)[::-1]: j,p = a[j] for i in range(2): for k in g[j]: if k == p: continue dp[i][j] += max( dp[1][k]+1-i, dp[0][k]) print(max(dp[0][0], dp[1][0]+1))