#include<bits/stdc++.h>
#define ll long long
using namespace std;
int N,tren,u1,u2,res,maximum,nput,potez,poz,oznaka2[100005],oznaka1[100005],oznaka[100005];
vector<int> stablo[100005];
queue<int> BFSq,stavi,specq;
bool prosli[100005];
void BFS(){
    while(BFSq.size()){
        tren=BFSq.front();
        oznaka[tren]=stavi.front();
        BFSq.pop();
        for(int i=0;i<stablo[tren].size();i++)
            if(oznaka[stablo[tren][i]]==-1){
                BFSq.push(stablo[tren][i]);
                stavi.push((stavi.front()+1));
            }
        stavi.pop();
    }
    return;
}
void DFS(int pozz){
    if(oznaka[pozz]==maximum)
        specq.push(pozz);
    prosli[pozz]=true;
    for(int i=0;i<stablo[pozz].size();i++)
        if(!prosli[stablo[pozz][i]]){
          //  cout<<stablo[pozz][i]<<" "<<oznaka[pozz]<<endl;
            DFS(stablo[pozz][i]);
        }
    return;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>N;
    if(N<=4){
        cout<<1<<endl;
        return 0;
    }
    for(int i=1;i<N;i++){
        cin>>u1>>u2;
        stablo[u1].push_back(u2);
        stablo[u2].push_back(u1);
        oznaka[i]=-1;
    }
    oznaka[N]=-1;
    for(int i=1;i<=N;i++)
        if(stablo[i].size()==1){
            BFSq.push(i);
            stavi.push(1);
        }
    BFS();
   // cout<<oznaka[1]<<" "<<oznaka[2]<<" "<<oznaka[3]<<" "<<oznaka[4]<<" "<<oznaka[5]<<endl;
    maximum=1;
    for(int i=1;i<=N;i++)
        maximum=max(maximum,oznaka[i]);
    for(int i=1;i<=N;i++)
        if(oznaka[i]==maximum)
            oznaka[i]=0;
        else oznaka[i]=-1;
    for(int i=1;i<=N;i++)
        if(oznaka[i]==0){
           BFSq.push(i);
           stavi.push(1);
           poz=i;
        }
    BFS();
    maximum=1;
    for(int i=1;i<=N;i++)
        maximum=max(maximum,oznaka[i]);
    DFS(poz);
    for(int i=1;i<=N;i++)
        prosli[i]=0;
    if(specq.size()%2==0)
        potez=1;
    else potez=0;
    for(int i=1;i<=N;i++){
        oznaka[i]=0;
        oznaka1[i]=-1;
    }
    BFSq.push(specq.front());
    stavi.push(0);
    while(BFSq.size()){
        tren=BFSq.front();
        oznaka1[tren]=stavi.front();
        BFSq.pop();
        for(int i=0;i<stablo[tren].size();i++)
            if(oznaka1[stablo[tren][i]]==-1){
                BFSq.push(stablo[tren][i]);
                stavi.push((stavi.front()+1));
            }
        stavi.pop();
    }
    for(int i=1;i<=N;i++)
        nput=max(nput,oznaka1[i]);
    //cout<<specq.size()<<endl;
    while(specq.size()){
      //  cout<<specq.front()<<" ";
        oznaka[specq.front()]=potez;
        potez=(potez+1)%2;
        specq.pop();
    }
   // cout<<endl;
    //cout<<oznaka[1]<<" "<<oznaka[2]<<" "<<oznaka[3]<<" "<<oznaka[4]<<" "<<oznaka[5]<<" "<<oznaka[6]<<endl;
    for(int i=1;i<=N;i++)
        if(oznaka[i]==1){
            poz=i;
            break;
        }
    //cout<<poz<<endl;
    BFSq.push(poz);
    stavi.push(0);
    while(BFSq.size()){
        tren=BFSq.front();
        oznaka2[tren]=stavi.front();
        prosli[tren]=1;
        BFSq.pop();
        for(int i=0;i<stablo[tren].size();i++)
            if(!prosli[stablo[tren][i]]){
                BFSq.push(stablo[tren][i]);
                stavi.push((stavi.front()+1));
            }
        stavi.pop();
    }
    //cout<<oznaka[1]<<" "<<oznaka[2]<<" "<<oznaka[3]<<" "<<oznaka[4]<<" "<<oznaka[5]<<endl;
    //cout<<oznaka2[1]<<" "<<oznaka2[2]<<" "<<oznaka2[3]<<" "<<oznaka2[4]<<" "<<oznaka2[5]<<endl;
    res=0;
    maximum=0;
  //  cout<<poz<<endl;
    for(int i=1;i<=N;i++){
        if(oznaka[i]==1)
            res=max(res,oznaka2[i]);
    }
    if(res==0)
        cout<<nput-1<<endl;
    else cout<<res<<endl;
    return 0;
}