#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+50;
ll n,dp[N][1];
vector<ll> g[N];
ll dfs(ll node,ll fa,ll s){
bool f=0;
ll an=-1;
for(auto k : g[node]){
if(k!=fa){
f=1;
an=max(dfs(k,node,s+1),an);
}
}
if(f==0){
dp[node][0]=s+1;
return 0;
}else{
return an+1;
}
}
int main(){
cin>>n;
for(int i=0,u,v;i<n-1;i++){
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
if(n==2){
cout<<"1";
return 0;
}if(n==3){
cout<<"2";
return 0;
}
ll p=dfs(1,0,0)+1;
for(int i=1;i<=n;i++){
if(dp[i][0]==p){
cout<<dfs(i,0,0)+1;
return 0;
}
}
}