import sys
from collections import deque

def main():
    n = int(sys.stdin.readline())
    adj = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        adj[a].append(b)
        adj[b].append(a)
    
    def get_farthest(start):
        visited = [-1] * (n + 1)
        q = deque([start])
        visited[start] = 0
        max_node = start
        max_dist = 0
        while q:
            u = q.popleft()
            for v in adj[u]:
                if visited[v] == -1:
                    visited[v] = visited[u] + 1
                    q.append(v)
                    if visited[v] > max_dist:
                        max_dist = visited[v]
                        max_node = v
        return max_node, max_dist
    
    # First BFS to find one end of the diameter
    u, _ = get_farthest(1)
    # Second BFS to find the other end and compute the diameter length
    v, diameter = get_farthest(u)
    
    print(2 * (n - 1) - diameter)

if __name__ == "__main__":
    main()