N = int(input()) UV = [list(map(int, input().split())) for _ in range(N - 1)] D = [0] * N E = [[] for _ in range(N)] for u, v in UV: u -= 1 v -= 1 E[u].append(v) E[v].append(u) def bfs(a): q = [a] cnt = 0 nv = [True] * N nv[a] = False while q: q2 = [] lastq = q[:] while q: x = q.pop(-1) for y in E[x]: if nv[y]: nv[y] = False q2.append(y) q, q2 = q2, q cnt += 1 return (cnt, lastq) cnt, lastq = bfs(0) cnt, lastq = bfs(lastq[0]) print(N - cnt)