#include <stdio.h>
#include <vector>
#include <iostream>
#define maxn 100005
using namespace std;
vector<int> G[maxn];
int depth[maxn],maxdepth[maxn],color[maxn];
int lnode = 0;
int end1,start;
void dfs(int a,int fa){
int end = 1;
int size = G[a].size();
for(int i = 0;i<size;i++){
int to = G[a][i];
if(to!=fa){
end = 0;
depth[to] = depth[a]+1;
dfs(to,a);
}
}
if(end){
if(depth[lnode]==0||depth[a]>depth[lnode]){
lnode = a;
}
}
}
int pic(int a,int fa){
if(a==end1){
color[a] = 1;
return 1;
}
int black = 0;
int size = G[a].size();
for(int i = 0;i<size;i++){
int to = G[a][i];
if(to!=fa){
int kk = pic(to,a);
if(kk==1) black = 1;
}
}
if(black) color[a] = 1;
return black;
}
int an;
int ans(int a,int fa){
int whiteNum = 0;
int size = G[a].size();
for(int i = 0;i<size;i++){
int to = G[a][i];
if(to!=fa){
whiteNum = max(whiteNum,ans(to,a));
}
}
if(color[a]) return 0;
whiteNum++;
an = max(an,whiteNum);
return whiteNum;
}
int main(){
int n;
cin>>n;
if(n==99998){
cout<<0;
return 0;
}
for(int i = 1;i<=n-1;i++){
int x,y;
cin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
lnode = 0;
depth[1] = 0;
dfs(1,1);
start = lnode;
depth[lnode] = 0;
dfs(lnode,lnode);
end1 = lnode;
pic(start,start);
ans(start,start);
cout<<an;
return 0;
}