#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

vector<int> mg[100005];
int marka[100005],naj,res,maks;

void dfs(int cvor,int r)
{
    int i,x;  marka[cvor]=1;
    if(r>maks) {maks=r; naj=cvor;}

    for(i=0;i<mg[cvor].size();i++)
    {
        x=mg[cvor][i];
        if(marka[x]==0) {marka[x]=1; dfs(x,r+1);}
    }
}

int main()
{
    ios::sync_with_stdio(false);

    int n,i,a,b,d,res;

    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>a>>b;
        mg[a].push_back(b);
        mg[b].push_back(a);
    }

    maks=0;
    dfs(1,0);
    for(i=1;i<=n;i++) marka[i]=0;
    maks=0;
    //cout<<"naj "<<naj<<endl;
    dfs(naj,0);

    d=maks;
    //cout<<maks<<endl;
    res=d;
    if(n%2==0) res--;
    if(d%2==1) res--;

    cout<<res;

    return 0;
}