from collections import deque n = int(input()) edges = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) queue = deque() queue.append(0) dist = [-1] * n dist[0] = True while queue: pos = queue.popleft() for npos in edges[pos]: if dist[npos] == -1: dist[npos] = dist[pos] + 1 queue.append(npos) queue.append(pos) dist = [-1] * n dist[pos] = 0 while queue: pos = queue.popleft() for npos in edges[pos]: if dist[npos] == -1: dist[npos] = dist[pos] + 1 queue.append(npos) print((n - 1) * 2 - max(dist))