#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1e5 + 5;
int n, u, w, x, y, i, j, d, p, m, r, max_p = -1, b[5];
vector<int> g[N];
bool spec;

void _dfs(int s, int e) {
	if (d > p) {
		p = d;
		m = s;
		r = 0;
	}
	if (d == p) {
		r++;
	}
	++d;
	for (auto u : g[s]) {
		if (u != e) _dfs(u, s);
	}
	--d;
}

bool prava() {
	for (i = 1; i <= n; i++) {
		if (g[i].size() != 2)return false;
	}
	return true;
}

void dfs(int s) {
	d = r = p = 0;
	_dfs(s, 0);
}

int main() {
	for (i = 0, cin >> n; i < n - 1; i++) {
		cin >> u >> w;
		g[u].push_back(w);
		g[w].push_back(u);
	}
	if (prava())return cout << n - 3 + (n & 1), 0;
	for (i = 1; i <= n; i++) {
		if (g[i].size() > 1)++j;
	}
	if (j < 2 && n>4)return cout << 2, 0;
	dfs(1);
	dfs(m);
	if (r == 1) {
		dfs(m);
		if (r == 1)spec = true;
	}
	cout << p - 1 + (n & 1) - spec;
}