#include<bits/stdc++.h>
#define MAXN (int)1e5+10
using namespace std;
int n, a, b, l;
vector<int> g[MAXN];
int mark[MAXN];
void bfs(int src)
{
    for(int i=1;i<=n;i++)mark[i]=-1;
    queue<pair<int, int>> q;
    q.push({src, src});
    while(!q.empty())
    {
        int v = q.front().first;
        int anc = q.front().second;
        q.pop();
        mark[v]=mark[anc]+1;
        for(auto x : g[v])if(mark[x]==-1)q.push({x, v});
    }
}
int main()
{
    cin >> n;
    for(int i=0;i<n-1;i++)
    {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bfs(1);
    l=0;
    for(int i=1;i<=n;i++)
    {
        if(mark[i]>l)
        {
            l=mark[i];
            a=i;
        }
    }
    bfs(a);
    l=0;
    for(int i=1;i<=n;i++)
    {
        if(mark[i]>l)
        {
            l=mark[i];
            b=i;
        }
    }
    if(n%2==0)
    {
        if(mark[b]%2==0)cout << mark[b];
        else
        {
            if(mark[b]==3)cout << 1;
            else cout << mark[b]-1;
        }
    }
    else cout << mark[b];
    return 0;
}