import sys sys.setrecursionlimit(10 ** 9) import pypyjit pypyjit.set_param('max_unroll_recursion=-1') from heapq import * n = int(input()) edges = [[] for _ in range(n)] for _ in range(n - 1): u, v = map(int, input().split()) u -= 1 v -= 1 edges[u].append(v) edges[v].append(u) def dfs(pos, bpos): hq = [] for npos in edges[pos]: if npos == bpos: continue else: tmp = dfs(npos, pos) if len(hq) > len(tmp): for t in tmp: heappush(hq, t) else: for h in hq: heappush(tmp, h) hq = tmp add = -1 for _ in range(2): if hq: add += heappop(hq) heappush(hq, add) return hq hq = dfs(0, -1) print(-hq[0])