#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int i;
	bool was[n]; 
	int k[n+1];
	for(i=0;i<n;i++)
	{
		 was[i]=false;
		 k[i+1]=0;
	}
	vector<int> v[n];
	int r=0;
	int maxa=0;
	for(i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
		if((int)v[a].size()>maxa)
		{
			maxa=v[a].size();
			r=a;
		}
		if((int)v[b].size()>maxa)
		{
			maxa=v[b].size();
			r=b;
		}
	}                 
	int u[n];
	for(i=0;i<n;i++)
		u[i]=n-1;
	list<int> q;
	q.push_back(r);
	u[r]=0;
	while(!q.empty())
	{
		int s=q.front();
		was[s]=true;
		q.pop_front();                      
		for(i=0;i<(int)(v[s].size());i++)
		{
			if(was[v[s][i]])
				continue;    
			q.push_back(v[s][i]);                
			u[v[s][i]]=min(u[v[s][i]],u[s]+1);
		}                         
	}
	for(i=0;i<n;i++)
		k[u[i]]++;
	//int ans=0;  
	bool ok=1;
	vector<int> resenje;
	for(i=1;i<=n;i++)
	{
		if(ok==true) 
		{ 
			if(k[i]>1 && k[i]<4)
				resenje.push_back(i);
			if(k[i]>=4) 
			{ 
				resenje.push_back(i); 
				resenje.push_back(i); 
			}
		} 
		else 
		{ 
			if(k[i]<3 && k[i]>0) 
			resenje.push_back(i); 
			if(k[i]>=3) 
			{ 
				resenje.push_back(i); 
				resenje.push_back(i); 
			} 
		} 
		if(k[i]%2==1) ok^=1;
	}
	if(resenje.size()==1)
		cout<<resenje[resenje.size()-1];
	else
		cout<<resenje[resenje.size()-1]+resenje[resenje.size()-2];
}