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

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;
}

void dfs(int s) {
	d = p = r = 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);
	}
	dfs(1);
	dfs(m);
	cout << p - 1;
	return 0;
}