

			import java.util.*;
			import java.io.*;
			class PT07Z
			{
				
				static HashMap<Integer,ArrayList> map=new HashMap<Integer,ArrayList>();
				static BitSet visited=new BitSet();
				
				public static void main(String args[])
				throws IOException
				{
					BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
					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(" ");
						int n1=Integer.parseInt(in[0]);
						int n2=Integer.parseInt(in[1]);
						
						if(map.containsKey(n1))
						{
							ArrayList recv=map.get(n1);
							recv.add(n2);
							map.put(n1,recv);
						}
						else
						{
							ArrayList st=new ArrayList();
							st.add(n2);
							map.put(n1, st);
						}
						if(map.containsKey(n2))// ki  kore??
						{
							ArrayList recv=map.get(n2);
							recv.add(n1);
							map.put(n2, recv);
						}
						else
						{
							ArrayList st=new ArrayList();
							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)
				{
					int max=Integer.MIN_VALUE;
					Queue<Integer> queue=new LinkedList();
					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)
				{
					int max=Integer.MIN_VALUE;
					Queue<Integer> queue=new LinkedList();
					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)
				{
					ArrayList al=map.get(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;
				}
			}