from collections import deque from heapq import * from sys import setrecursionlimit setrecursionlimit(400010) def main(): N=int(input()) Graph=[[]for i in range(N)] for i in range(N-1): x,y=map(int,input().split()) Graph[x-1].append(y-1) Graph[y-1].append(x-1) checked=[False]*N vec=[[]for i in range(N)] def dfs(i,parent): checked[i]=True for to in Graph[i]: if not checked[to]: p=dfs(to,i) heappush(vec[i],-p) max_size=len(vec[i]) index=i for to in Graph[i]: if to!=parent and len(vec[to])>max_size: index=to max_size=len(vec[to]) if index!=i: for j in vec[i]: heappush(vec[index],j) vec[i].clear() for to in Graph[i]: if index!=to and to!=parent: for j in vec[to]: heappush(vec[index],j) vec[to].clear() vec[i]=vec[index] res=1 if len(vec[i])<=2: for j in vec[i]: res+=-j vec[i].clear() else: for j in range(2): res+=-heappop(vec[i]) return res ans=dfs(0,-1) print(ans) return main()