#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],brojac[100005],i,j,x,y,poc,odg,d,tr,mark[100005],duz[100005],duz1[100005];
//0- nema jednakost, 1- tacno 1 od dva ima jednakost, 2- oba imaju jednakost
//2 lanca se seku i n neparno ili ii i n parno odg=d-1, n neparno 1 lanac odg=d-2, n parno 1 lanac odg=d-3  
vector<long long>grane[100005];
void resi(long long x)
{
	int ind1=0,ind2=0,x1=0,y1=0,t=0;
	mark[x]=1;
	if(grane[x].size()==1)
	{
		duz[x]=1;
		duz1[x]=1;
		a[x]=0;
	return;
    }
    
	for(int ii=0;ii<grane[x].size();ii++)
	{
	if(mark[grane[x][ii]]==0)
	{
		brojac[x]++;
	resi(grane[x][ii]);
	if(duz[grane[x][ii]]>=x1 && x1<=y1)
    {
	x1=duz[grane[x][ii]];
    ind1=(a[grane[x][ii]]+1)/2;
	}
    
    else
	if(duz[grane[x][ii]]>=y1 && y1<x1)
    {
	y1=duz[grane[x][ii]];
	ind2=(a[grane[x][ii]]+1)/2;
	}
    }
	}
	a[x]=ind1+ind2;
duz[x]=max(x1,y1)+1;
duz1[x]=x1+y1+1;
if(x1==y1 && a[x]!=2)
a[x]=1;
//cout<<x<<"  "<<duz1[x]<<endl;
}

main()
{
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(i=1;i<=n-1;i++)
	{
		cin>>x>>y;
		grane[x].push_back(y);
		grane[y].push_back(x);
	}
	
	for(i=1;i<=n;i++)
	if(grane[i].size()>1)
	{
	poc=i;
	i=n+2;
    }
    
    resi(poc);
    
    d=duz1[1];
    for(i=2;i<=n;i++)
    if(duz1[i]>d)
d=duz1[i];

tr=0;
for(i=1;i<=n;i++)
if(duz1[i]==d)    
if(tr<a[i])
tr=a[i];

odg=d-3+tr;
if(n%2==1)
odg++;

if(odg>d-1)
odg=d-1;
cout<<odg;
return 0;
}
/*34
1 3 2 3 3 4 4 5 4 6
4 8 8 7 8 9 8 10 10 11
11 17 17 21 17 22 11 27 
27 23 27 25 25 24 25 26
11 34 34 28 34 29 34 30 
34 33 33 32 33 31 10 12 
12 13 12 16 13 14 13 15
16 19 19 18 19 20
*/