// #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair P; typedef pairIP; typedef vector V; typedef vector V2; typedef vector > G; void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));} void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);} #define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++) #define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++) #define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--) #define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--) template void chmax(T &a, const T &b){if(a < b){a = b;}} template void chmin(T &a, const T &b){if(a > b){a = b;}} const ll INF = 1145141919; const ll MOD = 1000000007; const ll NUM = 101010; V path[101010]; ll dep[101010]; ll N; void bfs(ll rt){ rep1(i, N)dep[i] = INF; queueQ; Q.push(rt); dep[rt] = 0; while(!Q.empty()){ ll idx = Q.front(); Q.pop(); for(auto to : path[idx]){ if(dep[to] == INF){ dep[to] = dep[idx] + 1; Q.push(to); } } } } int main(){ cin >> N; rep(i, N - 1){ ll a, b; cin >> a >> b; path[a].push_back(b); path[b].push_back(a); } bfs(1); ll nxt = 1; rep1(i, N)if(dep[i] > dep[nxt])nxt = i; bfs(nxt); ll tmp = 0; rep1(i, N)chmax(tmp, dep[i]); cout << N - 1 - tmp << endl; return 0; }