#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=10005;
vector<int> h[N];
int n,ans,d1[N],d2[N];
void dfs(int u,int fa)
{
d1[u]=d2[u]=0;
for(int v=0;v<h[u].size();v++)
{
if(v==fa) continue;
dfs(v,u);
int t=d1[v]-1;
if(t>d1[u]) d2[u]=d1[u],d1[u]=t;
else d2[u]=t;
}
ans=max(ans,d1[u]+d2[u]);
}
signed main()
{
cin>>n;
for(int i=1;i<n;i++)
{
int x,y;
cin>>x>>y;
h[x].push_back(y);
h[y].push_back(x);
}
dfs(1,0);
cout<<ans<<endl;
return 0;
}
树形dp