#include <bits/stdc++.h>
using namespace std;

vector<int> najdalji;
void trazi(vector<vector<long> > t,long n, long daljina, long prethodni, long &res, int &br) {
    if (t[n].size()==1&&daljina!=0) {
        if (daljina>res) {
            res=daljina;
            br=1;
            najdalji.clear();
            najdalji.push_back(n);
        }
        else if (daljina==res) {
            br++;
            najdalji.push_back(n);
        }
        else return;
    }
    for (long i=0;i<t[n].size();i++) {
        if (t[n][i]==prethodni) continue;
        trazi(t,t[n][i],daljina+1,n,res,br);
    }
}
int naj4(vector<vector<long> > t, long n) {
    int br=0;
    long res=0;
    trazi(t,n,0,-1,res,br);
    if (br==1) return res-2;
    else {
        for (int k=0;k<najdalji.size();k++) {
            int br1=0;
            long res1=0;
            trazi(t,najdalji[k],0,-1,res1,br1);
            if (res1==res&&br1>1) {
                return res;
            }
        }
        return res-1;
    }
}
int naj3(vector<vector<long> > t, long n) {
    int br=0;
    long res=0;
    trazi(t,n,0,-1,res,br);
    if (br==1) return res-1;
    else return res;
}
int main() {
     long n;
     long a,b;
     scanf("%ld",&n);
     vector<vector<long> > t;
     t.resize(n+1);
     for (long i=0; i<n-1; i++) {
        scanf(" %ld %ld",&a,&b);
        t[a].push_back(b);
        t[b].push_back(a);
     }
     if (n%2==1) {
        int res=0;
        int p=0;
        for (long i=1;i<n;i++) {
            if (t[i].size()>1) continue;
            p=naj3(t,i);
            if (p>res) res=p;
        }
        printf("%d",res);
     }
     else if (n%2==0) {
        int res=0;
        int p=0;
        for (long i=1;i<n;i++) {
            if (t[i].size()>1) continue;
            p=naj4(t,i);
            if (p>res) res=p;
        }
        printf("%d",res);
     }
}