N = int(input()) V = [[] for _ in range(N)] for _ in range(N-1): a, b = map(int, input().split()) V[a-1].append(b-1) V[b-1].append(a-1) def dfs(prev, i, n): if len(V[i]) == 1 and V[i][0] == prev: return (n, i) rtn = (-1, -1) for j in V[i]: if j != prev: rtn = max(rtn, dfs(i, j, n+1)) return rtn n, u= dfs(-1, 0, 0) n, v = dfs(-1, u, 0) print(2*(N-1)-n)