#include <bits/stdc++.h>

using namespace std;

int max_count = 0;
int farthest = 0;

void dfs(int node, vector<vector<int>> nodes, set<int> visited, int count)
{
    visited.emplace(node);
    if (count > max_count)
    {
        max_count = count;
        farthest = node;
    }
    for(int i=0;i<nodes[node].size();i++)
    {
        if(visited.find(nodes[node][i])==visited.end())
        {
            dfs(nodes[node][i], nodes, visited, count+1);
        }
    }
}


int main()
{
    int n, u, v;
    cin >> n;
    vector<vector<int>> nodes(n+1);
    set<int> visited;
    for(int i=0;i<n-1;i++)
    {
        cin >> u >> v;
        nodes[u].push_back(v);
        nodes[v].push_back(u);
    }
    // for(int i=0;i<nodes.size();i++)
    // {
    //     for(auto x:nodes[i])
    //     {
    //         cout << x << " ";
    //     }
    //     cout << endl;
    // }

    bool chain = true;
    for(int i = 1;i<n;i++)
    {
        if (nodes[i].size() !=1 || nodes[i][0] != i+1)
        {
            chain = false;
        }
    }
    if(chain)
    {
        if(n%2==0)
        {
            cout << n-3;
        }
        else
        {
            cout << n-2;
        }
    }
    else
    {
        dfs(1,nodes,visited,0);
        visited.clear();
        dfs(farthest, nodes, visited, 0);
        int diameter = max_count;
        if(n%2!=0)
        {
            cout << diameter;
        }
        else
        {
            cout << diameter-1;
        }
        
    }
    

    return 0;
}