#include<iostream>
#include<vector>
#include<iterator>
#include<stdio.h>

using namespace std;

vector <bool> visited;
vector <int> longest_path;
vector <bool> was;

vector < vector<int> > graph;

int max_path = 0;

void longest_from_node(int v,int path)
{
	
	if(was[v] == true) return;
	
	//cout << "LFN in node: "<< v+1 <<endl;
	path++;
	longest_path[v] = path;
	if(path > max_path) max_path = path;
	
	visited[v] = true;
	
	for(vector<int>::iterator it = graph[v].begin(); it != graph[v].end(); it++)
    {
        if( ! visited[*it]) //note that *it repr the adj vert
        {
            longest_from_node(*it,path);
        }
    }

}

int main()
{

	int NO;
	int u,v,way = 0,c;
	scanf("%d",&NO);

	graph = vector< vector<int> > (NO);
	c = NO-1;
	while(c--)
	{
		scanf("%d %d", &u, &v);
		u--;
		v--;
		
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	longest_path = vector <int> (NO,0);
	visited = vector <bool> (NO,0);
	was = vector<bool> (NO,0);
	//longest_paths = vector<vector<int>> (NO);
	//new_longest_path = vector<int> (NO,0);
	int new_longest_path = 0;
	for(int i = 0; i < NO; i++)
	{
		max_path = 0;
		visited = vector <bool> (NO,0);
		int current_longest = 0;
		int current_2nd_longest = 0;
		int pom;
		was[i] = true;
		for(vector<int>::iterator it = graph[i].begin(); it != graph[i].end(); it++)
		{		
				if(was[*it] == true) continue;
				//cout << "Curret parent: "<< i+1 <<endl;
				max_path = 0;
				longest_from_node(*it,-1);
				
				if(max_path > current_longest)
				{
					current_2nd_longest = current_longest;
					current_longest = max_path;
					
					
					//cout << "\tNode: "<< (*it + 1) << " new local longest_path = "<<max_path << endl;
					//cout << "\tso 2nd = " << current_2nd_longest<<endl;
				}
				else
				{
					if(max_path > current_2nd_longest) current_2nd_longest = max_path;
					//cout << "\tNode: "<< (*it + 1) << " just new 2nd = " << current_2nd_longest<<endl;
				}
				
				if(current_2nd_longest == 0)
					pom = current_longest + current_2nd_longest  + 1;
				else
					pom = current_longest + current_2nd_longest  + 2;					
				if(pom > new_longest_path)
				{
					new_longest_path = pom;
					//cout << "\tNode: " << i+1 << " gives us new global longest path = " <<new_longest_path<<endl;
				}
						 
							
		}
		
		
	}
	
	printf("%d\n", new_longest_path);
	

}
