from collections import defaultdict, deque n = int(input()) G = defaultdict(list) C = [0 for _ in range(n)] for _ in range(n - 1): u, v = map(int, input().split()) u -= 1 v -= 1 G[u].append(v) G[v].append(u) for u in range(n): if C[u] >= 3: for v in G[u]: G[v].remove(u) G[u] = set() C[u] = 0 DP = [[0, 0] for _ in range(n)] Stack = [(0, -1, 0)] while Stack: cp, pp, m = Stack.pop() if m == 0: Stack.append((cp, pp, -1)) for np in G[cp]: if np == pp: continue Stack.append((np, cp, 0)) else: for np in G[cp]: if np == pp: continue DP[cp][0] += max(DP[np][0] - 1, DP[np][1]) DP[cp][1] += max(DP[np]) DP[cp][0] += 1 print(max(DP[0]))