#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
vector<int> g[maxn], v;
ll cnt[maxn], n;
ll dist(ll u, ll v){
	bool visited[maxn]={0};
	int d[maxn]={};
	queue<int> q;
	d[u]=0;
	q.push(u);
	visited[u]=true;
	while(!q.empty()){
		int x=q.front();q.pop();
		for(auto i:g[x]){
			if(!visited[i]){
				d[i]=d[x]+1;
				q.push(i);
				visited[i]=true;
			}
		}
	}
	return d[v];
}
int main()
{
	int n;
	cin >> n;
	bool pom=true;
	for(int i=1;i<n;i++){
		int u, v;
		cin >> u >> v;
		if(u+1!=v)pom=false;
		g[u].push_back(v);
		g[v].push_back(u);
		cnt[u]++,cnt[v]++;
	}
	if(pom)return cout << (n-1)/2, 0;
	int leaf=0,nije=0;
	for(int i=1;i<=n;i++){
		if(cnt[i] == 1){
			v.push_back(i);
		}
	}	
	leaf=v.size();
	nije=n-leaf;
	if(nije == 1)return cout << 2, 0;
	if(leaf == 2)return cout << (n-1)/2, 0;
	ll ans=0;
	for(int i=0;i<v.size();i++){
		for(int j=0;j<v.size();j++){
			if(i == j)continue;
			ans=max(ans,dist(v[i],v[j]));
		}
	}
	cout << ans << endl;
	return 0;
}
/*
6
1 2
2 3
2 4
1 5
1 6
*/