#include<bits/stdc++.h>
#define maxn 100010
using namespace std;

int n, ans, maxD, farV, d1, d2, d3;
vector<vector<int> > gr;
bool was[maxn];

void resetD(){
	farV = 0;
	for(int i = 1; i <= n; ++i){
		was[i] = 0;
	}
	maxD = 0;
}

void dfs(int x, int curD){
	was[x] = 1;
	maxD = max(curD, maxD);
	if(maxD == curD){
		farV = x;
	}
	for(int i : gr[x]){
		if(was[i]){
			continue;
		}
		dfs(i, curD + 1);
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	cin >> n;
	gr.resize(n+1, vector<int>());
	for(int i = 0; i < n-1; ++i){
		int x, y;
		cin >> x >> y;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	dfs(1, 0);
	int u = farV;
	resetD();
	dfs(u, 0);
	int v = farV;
	d1 = maxD;
	resetD();
	cerr << u << '\n' << v << '\n';
	was[v] = 1;
	was[u] = 1;
	for(int i = 1; i < n+1; ++i){
		if(!was[i]){
			dfs(i, 0);
			break;
		}
	}
	int tmp = farV;
	resetD();
	was[u] = 1;
	was[v] = 1;
	dfs(tmp, 0);
	d2 = maxD;
	cerr << d2 << '\n';
	if(n == 2){
		cout << "0\n";
		return 0;
	}
	if(d1 == max(d2, d3)){
		cout << d1 << '\n';
	} else {
		if(d1 % 2){
			cout << d1-2 << '\n';
		} else {
			cout << d1-1 << '\n';
		}
	}
}