#include <bits/stdc++.h>

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

int n;

vector< vector<int> > e;

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

    for(int i=0;i<sizee;i++){
        if(e[current][i]==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;
}
G dfs(int prev,int current,int &ignore)
{
    int sizee= e[current].size();
    G maxx={-1,-1};
    G temp;

    for(int i=0;i<sizee;i++){
        if(e[current][i]==ignore||e[current][i]==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);
    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);
    G thirddfs = dfs(firstdfs.v,firstdfs.v,seconddfs.v);
    cout << thirddfs.l << endl;
    return 0;
}