import java.util.*;
import java.io.*;
class PT07Z
{
static HashMap
<Integer,ArrayList
> map
=new HashMap
<Integer,ArrayList
>();
public static void main
(String args
[]) {
int n
=Integer.
parseInt(br.
readLine().
trim()); //long start=System.nanoTime();
for(int i=0;i<(n-1);i++)
{
String in
[]=br.
readLine().
trim().
split(" ");
if(map.containsKey(n1))
{
recv.add(n2);
map.put(n1,recv);
}
else
{
st.add(n2);
map.put(n1, st);
}
if(map.containsKey(n2))// ki kore??
{
recv.add(n1);
map.put(n2, recv);
}
else
{
st.add(n1);
map.put(n2, st);
}
//
}
int first_end_vertex=bfs_first(1);
//System.out.println(first_end_vertex);
visited.clear();
int max_length=bfs_second(first_end_vertex);
System.
out.
println(max_length
-1); //System.out.println((System.nanoTime()-start)/1000000000.0);
}
static int bfs_first(int start)
{
queue.add(start);
visited.set(start);
int node=0,level=0,lastnode=0,no_of_children=0;
while(!queue.isEmpty())
{
node=queue.remove();
//finding out all the unvisited child nodes adjacent to node
int child=0;
while((child=get_unvisited_childnode(node))!=0)
{
visited.set(child);
queue.add(child);
no_of_children++;
}
if((queue.size()-no_of_children==0))
{
level++;
no_of_children=0;
}
if(level>max)
{
max=level;
lastnode=node;
}
}
return lastnode;
}
static int bfs_second(int start)
{
queue.add(start);
visited.set(start);
int node=0,level=0,lastnode=0,no_of_children=0;
while(!queue.isEmpty())
{
node=queue.remove();
//finding out all the unvisited child nodes adjacent to node
int child=0;
while((child=get_unvisited_childnode(node))!=0)
{
visited.set(child);
queue.add(child);
no_of_children++;
}
if((queue.size()-no_of_children==0))
{
level++;
no_of_children=0;
}
if(level>max)
{
max=level;
lastnode=node;
}
}
return level;
}
static int get_unvisited_childnode(int node)
{
Iterator<Integer> list_iterator=al.iterator();
while(list_iterator.hasNext())
{
int hold=list_iterator.next();
if(!visited.get(hold))
{
//now mark the node as visited
visited.set(hold);
return hold;
}
}
return 0;
}
}
CgoJCQlpbXBvcnQgamF2YS51dGlsLio7CgkJCWltcG9ydCBqYXZhLmlvLio7C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