//Failure will never overtake me if my determination to succeed is strong enough
#include <bits/stdc++.h>

using namespace std;

int dijametar = 0, najd = -1;

void dfs(int p, int u, vector<int> a[], int x)
{
    x++;
    if(x > dijametar)
    {
        dijametar = x;
        najd = u;
    }

    for(auto i: a[u])
    {
        if(i != p)
            dfs(u, i, a, x);
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a[n];
    for(int i = 0; i < n-1; i++)
    {
        int x, y;
        cin >> x >> y;
        a[x-1].push_back(y-1);
        a[y-1].push_back(x-1);
    }


    dfs(-1, 0, a, 0);

    dfs(-1, najd, a, 0);

    cout << dijametar-2-(dijametar%2==0);

}