#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); ++i) //#define cerr if(false) cerr #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); using namespace std; using ll = long long; using pii = pair; template ostream &operator<<(ostream &os, pair a){ os << '(' << a.first << ',' << a.second << ')'; return os; } template ostream &operator<<(ostream &os, vector v){ for(auto x:v)os << x << ' '; return os; } void debug(){cerr << '\n';} template void debug(H a, T... b){ cerr << a; if(sizeof...(b))cerr << ", "; debug(b...); } vectorg[100005]; int ans; int dfs(int s,int p){ // show(s); int temp = 0; vectora; for(int x:g[s]){ if(x == p)continue; a.push_back(dfs(x,s)); } sort(a.rbegin(),a.rend()); if(a.size()>1)ans = max(ans,a[0]+a[1]+2); if(a.size()){ ans = max(ans, a[0] + 1); temp = max(temp, a[0] + 1); } return temp; } int main(){ int n; cin >> n; rep(i,n-1){ int a,b; cin >> a >> b; a--,b--; g[a].push_back(b); g[b].push_back(a); } dfs(0,-1); cout << n-1-ans << endl; }