import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < n - 1; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a); } PriorityQueue queue = new PriorityQueue<>(); int[] costs = new int[n]; queue.add(new Path(0, 0)); search(graph, queue, costs); int max = 0; int maxIdx = 0; for (int i = 0; i < n; i++) { if (max < costs[i]) { max = costs[i]; maxIdx = i; } } queue.add(new Path(maxIdx, 0)); search(graph, queue, costs); Arrays.sort(costs); System.out.println(n - costs[n - 1] - 1); } static void search(ArrayList> graph, PriorityQueue queue, int[] costs) { Arrays.fill(costs, Integer.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value + 1)); } } } static class Path implements Comparable { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }