#include <iostream>
#include <vector>
#include <list>
using namespace std;
vector<list<int> > g;
bool *pos;
int j;
int m, pm, mi, ppm;
void dfs(int v, int d)
{
	pos[v] = 1;
	if(d > m)
	{
		m = d;
		ppm = pm;
		pm = 1;
		mi = v;
		/*j = !j;
		a[j] = new int [n+1];
		for()
		a[j][0] = 1;
		a[j][v] = 1;
		*/
	}
	else if(d == m) pm++;
	else if(d == m-1) ppm++;
	for(list<int>::iterator it = g[v].begin(); it != g[v].end(); it++)
		if(!pos[*it])
			dfs(*it, d+1);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, x, y;
	cin >> n;
	g.resize(n+1);
	pos = new bool[n+1];
	for(int i = 0; i <= n; i++) pos[i] = 0;
	for(int i = 0; i < n-1; i++)
	{
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	m = pm = ppm = 0;
	dfs(1, 0);
	int am = pm, apm = ppm;
	m = pm = ppm = 0;
	for(int i = 0; i <= n; i++) pos[i] = 0;
	dfs(mi, 0);
	int bm = pm, bpm = ppm;
	if(n % 2)
		if(am > 1 || bm > 1) cout << m;
		else cout << m-1;
	else
		if(am > 1 && bm > 1) cout << m;
		else
			if(am == 1)
				if(bm > 1) cout << m-1;
				else
					if(apm == 1 || bpm == 1) cout << m-2;
					else cout << m-1;
			else cout << m-1;
}