import collections INF = 10 ** 8 def breadth_first_search(adj_list, start_v): n = len(adj_list) visited = [False] * n pred = [None] * n dist = [INF] * n q = collections.deque() q.append(start_v) visited[start_v] = True dist[start_v] = 0 while q: u = q.popleft() for v in adj_list[u]: if not visited[v]: visited[v] = True pred[v] = u dist[v] = dist[u] + 1 q.append(v) return pred, dist def solve(adj_list): n = len(adj_list) s = 0 _, dist_a = breadth_first_search(adj_list, s) u = max(range(n), key=lambda x: dist_a[x]) pred, dist_b = breadth_first_search(adj_list, u) v = max(range(n), key=lambda x: dist_b[x]) path = [v] while path[-1] != u: path.append(pred[path[-1]]) res = 0 for w in path: if w != v and w != u: res += len(adj_list[w]) - 2 return res def main(): n = int(input()) adj_list = [set() for _ in range(n)] for _ in range(n - 1): a, b = (int(z) - 1 for z in input().split()) adj_list[a].add(b) adj_list[b].add(a) print(solve(adj_list)) if __name__ == "__main__": main()