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

typedef long long ll;
typedef long double ld;

int dist[5][100005];
int cnt;
int far;

queue <int> q;

bool visited[100005];
vector <int> graf[100005];

void bfs(int root){
    queue <int> t;
    t.push(root);
    visited[root] = 1;
    while(!t.empty()){
        int v = t.front();
        t.pop();
        q.push(v);
        for(auto c : graf[v]){
            if(!visited[c]){
                visited[c] = 1;
                t.push(c);
            }
        }
    }
}

int color[100005];
int maxdis;

void dfs(int v, int dis){
    if(color[v] == 0 && dis > maxdis){
        far = v;
        maxdis = dis;
    }
    dist[cnt][v] = dis;
    for(auto c : graf[v]){
        if(dist[cnt][c] == 0) dfs(c, dis+1);
    }
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

	int n;
	cin >> n;
	for(int i=1; i<n; i++){
        int a, b;
        cin >> a >> b;
        graf[a].push_back(b);
        graf[b].push_back(a);
	}
	far = 1;
	dfs(1, 1);
	cnt++;
	maxdis = 0;
	dfs(far, 1);
	cnt++;
	int center = 0;
	maxdis = 0;
	dfs(far, 1);
	cnt++;
	//cout << dist[1][1] << " " << dist[2][1] << endl;
	for(int i=1; i<=n; i++){
        if(abs(dist[1][i]-dist[2][i]) <= 1 && dist[1][i]+dist[2][i] == maxdis+1) center = i;
	}
	bfs(center);
	int g = 0;
	while(!q.empty()){
        color[q.front()] = g;
        q.pop();
        g = 1-g;
	}
	maxdis = 0;
	far = center;
	//cout << center << endl;
	dfs(far, 1);
	cnt++;
	maxdis = 0;
	dfs(far, 1);
	//for(int i=1; i<=n; i++) cout << color[i] << " ";
	cout << maxdis-1 << "\n";
    return 0;
}