#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[100005];
int n;
int vis[100005];
int dis[100005];
int dfs(int x,int d){
vis[x] = 1;
dis[x] = d;
for(int i = 0; i < v[x].size(); i++){
if(!vis[v[x][i]]){
dfs(v[x][i],d+1);
}
}
}
int main(){
while(scanf("%d",&n) != EOF){
int x,y;
for(int i = 1; i < n; i++){
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
memset(vis,0,sizeof(vis));
dfs(1,0);
int ans = 0,tmp;
for(int i = 1; i <= n; i++){
if(ans < dis[i]){
ans = dis[i];
tmp = i;
}
}
memset(vis,0,sizeof(vis));
dfs(tmp,0);
for(int i = 1; i <= n; i++){
if(ans < dis[i])
ans = dis[i];
}
printf("%d\n",ans);
}
return 0;
}