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


int totalNodes(vector<int> adjac[], int n,int x, int y)
{

    bool pos[n+1] = {0};


    int p[n] ;

    queue<int> q;
    q.push(x);



    int m;


    while (!q.empty())
    {
        m = q.front() ;
        q.pop();
        for (int i=0; i<adjac[m].size(); ++i)
        {
            int h = adjac[m][i];
            if (!pos[h])
            {
                pos[h] = true;


                p[h] = m ;
                q.push(h);
            }
        }
    }

    int count = 0;


    int i = p[y];
    while (i != x)
    {


        count++;

        i = p[i];
    }

    return count ;
}

int main()
{
   int n,a,b,maxa,k=1;
   cin>>n;
   if(n>4)
   {
        vector < int > adjac[n+1];
        for(int i=0;i<n-1;i++)
        {
            cin>>a>>b;
            adjac[a].push_back(b);
            adjac[b].push_back(a);
        }
        maxa=1+totalNodes(adjac,n,a,b);
        for(int i=1;i<n;i++)
            for(int j=i+1;j<n+1;j++)
                if(maxa<1+totalNodes(adjac, n, i, j))
                    {
                        maxa=1+totalNodes(adjac,n,i,j);
                        k++;
                    }

        if(k%2==0)
            cout<<maxa;
        else
            cout<<maxa-1;
   }
   else cout<<1;
    return 0;
}