#include <bits/stdc++.h>
using namespace std;
vector <int> k[100005];
queue <int> q;
int n,u,v,p[100005],d[100005],dmax,b;
void bfs(int a){
    memset(p,0,sizeof(p));
    memset(d,-1,sizeof(d));
    p[a]=1;
    q.push(a);
    d[a]=0;
    while(q.size()){
            a=q.front();
        for (int i=0;i<k[a].size();i++){
                   if (p[k[a][i]]==0){
                      q.push(k[a][i]);
                      p[k[a][i]]=1;
                      d[k[a][i]]=d[a]+1;
                   }
                 q.pop();
        }
    }
}
int main () {
scanf("%d",&n);
for (int i=1;i<=n-1;i++){
    scanf("%d%d",&u,&v);
    k[u].push_back(v);
    k[v].push_back(u);
}
bfs(1);
for (int i=1;i<=n;i++){
    if (d[i]>dmax){
        dmax=d[i];
        b=i;
    }
}
dmax=0;
bfs(b);
for (int i=1;i<=n;i++){
  if (d[i]>dmax){
        dmax=d[i];
    }
}
printf("%d\n",dmax);


return 0;
}