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

#define pb push_back

int n;
vector<int> g[100005];
bool visited[100005];
int maxD, node1;

void dfs(int node, int d)
{
    visited[node] = true;
    if(d > maxD){
        maxD = d;
        node1 = node;
    }

    for(auto c : g[node]){
        if(!visited[c]){
            dfs(c, d + 1);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    for(int i = 0; i < n - 1; ++i){
        int u, v;
        cin >> u >> v;

        g[u].pb(v);
        g[v].pb(u);
    }

    dfs(1, 0);
    for(int i = 1; i <= n; ++i){visited[i] = false;}
    maxD = 0;
    dfs(node1, 0);

    if(maxD + 1 == n){cout << maxD - (maxD % 2) - 1 << "\n";}
    else{cout << maxD << "\n";}

    return 0;
}