#include <bits/stdc++.h>

    using namespace std;
    struct G{int v,l;};

    int n;

    vector< vector<int> > e;
    vector<bool> ignoree (10000,0);

    G dfs(int prev,int current)
    {
        int sizee= e[current].size();
        G maxx={-1,-1};
        G temp;

        for(int i=0;i<sizee;i++){
            int next = e[current][i];
            if( ignoree[next]==true || next==prev)continue;
            temp=dfs(current,e[current][i]);
            if(temp.l>maxx.l)
                maxx=temp;
        }
        maxx.l++;
        if(maxx.l==0)
            maxx.v=current;
        return maxx;
    }


    int main()
    {
        int x,y;
        cin>>n;
        e = vector<vector<int> > (n);
        ignoree=vector<bool> (n,0);
        for(int i=0;i<n-1;i++){
            cin>>x>>y;
            e[x-1].push_back(y-1);
            e[y-1].push_back(x-1);
        }
        G firstdfs=dfs(0,0);
        G seconddfs = dfs(firstdfs.v,firstdfs.v);
        ignoree[seconddfs.v]=1;
        ignoree[firstdfs.v]=1;
        G thirddfs = dfs(firstdfs.v,firstdfs.v);
        G dfs4= dfs(seconddfs.v,seconddfs.v);
        if(n%2){
            cout<<max(thirddfs.l,dfs4.l)<<endl;
            return 0;
        }
        G dfsA = dfs(dfs4.v,dfs4.v);
        G dfsB = dfs(thirddfs.v,thirddfs.v);
        cout << max(dfsA.l,dfsB.l) << endl;

        return 0;
    }