#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = (int)1e5+99;
int n, pr, dr;
pair<int, int> posl;
vector<int> graf[N];
int bfs(int poc) {
    vector<bool> pos(n+1, 0);
    queue<pair<int, int> > q;
    vector<int> broj(n, 0);
    broj[0]=1;
    q.emplace(make_pair(poc, 0));
    while(!q.empty()) {
        pair<int, int> node = q.front(); q.pop(); posl=node;
        pos[node.first]=1;
        for(auto x:graf[node.first])
            if(!pos[x]) {
                ++broj[node.second+1];
                q.emplace(make_pair(x, node.second+1));
            }
    }
    return posl.second-((broj[posl.second]==1) ? 1:0);
}
int main() {
    IOS; cin >> n;
    for(int i=0; i<n-1; ++i) {
        int u,v; cin >> u >> v;
        graf[u].push_back(v);
        graf[v].push_back(u);
    }
    int kec=0, dva=0;
    for(int i=1; i<=n; ++i) {
        if(graf[i].size()==1) ++kec;
        else if(graf[i].size()==2) ++dva;
    }
    if(dva==2 && kec==n-2 && n!=3 && n!=4) {cout << (n+1)/2; return 0;}
    else if(n==3 || n==4) {cout << 1; return 0;}
    int pr=0, dr=0;
    pr = bfs(1);
    pr = bfs(posl.first);
    dr = bfs(posl.first);
    //cout << pr << ' ' << dr;
    if(n%2) cout << max(pr, dr);
    else cout << min(pr, dr);
    return 0;
}