import java.util.*;

public class Solution {
	
	static int[] visited = new int[200000];
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Node map = null;
		
		int relations  = sc.nextInt();
		
		int[][] links = new int[relations][2];
		
		Node[] nodes = new Node[200000];
		
		int min = Integer.MAX_VALUE;
		for(int r=0;r<relations;r++){
			int first = sc.nextInt();
			int second = sc.nextInt();
			if(first < min){
				min = first;
			}
			if(second < min){
				min = second;
			}
			if(nodes[first] == null){
				Node newConn = new Node(first, null);
				nodes[first] = newConn;
			}
			if(nodes[second] == null){
				Node newConn = new Node(second, null);
				nodes[second] = newConn;
			}
				links[r][0] = first;
				links[r][1] = second;
		}
		
		sc.close();
		
		for(int i=0;i<relations;i++){
			nodes[links[i][0]].AddConnection(nodes[links[i][1]]);
			nodes[links[i][1]].AddConnection(nodes[links[i][0]]);
		}
		 map = nodes[min]; 

		visited = new int[200000];
		Node emptyNode = ScanForEmpty(map);
		visited = new int[200000];
		int maxD = CalculateMaxDepth(emptyNode);
		System.out.println(maxD/2);
	}
	
	static int CalculateMaxDepth(Node currNode){
		
		if(visited[currNode.value] == 1){
			return -1;
		}
	    visited[currNode.value] = 1;
	    
	    int maxBranchDepth = 1;
	    for(int i=0;i<currNode.connections.size();i++){
	    	int branchDepth = 1 + CalculateMaxDepth(currNode.connections.get(i));
	    	if(branchDepth > maxBranchDepth){
	    		maxBranchDepth = branchDepth;
	    	}
	    }
	    return maxBranchDepth;
	}
	
	static Node ScanForEmpty(Node currNode){
		
		if(visited[currNode.value] == 1){
			return null;
		}
	    visited[currNode.value] = 1;
	    
	    if(currNode.connections.size() == 1){
			return currNode;
		}
	    
	    Node found = null;
	    for(int i=0;i<currNode.connections.size();i++){
	    	found = ScanForEmpty(currNode.connections.get(i));
	    	if(found != null){
	    		break;
	    	}
	    }
	    return found;
	}
	
	static Node FindNode(Node currNode, int value){
	    
	    if(currNode.value == value){
	        return currNode;   
	    }
	    else if(currNode.connections.size() == 0){
	        return null;
	    }
	    
	    if(visited[currNode.value] == 1){
			return null;
		}
	    visited[currNode.value] = 1;
	    Node found = null;
	    for(int i=0;i<currNode.connections.size();i++){
	        found = FindNode(currNode.connections.get(i), value);
	        if(found != null){
	            break;
	        }
	    }
	    return found;
	}
	
}

class Node{
	
	int value;
	ArrayList<Node> connections = new ArrayList<Node>();
	
	public Node(int from, Node to){
		this.value = from;
		if(to != null){
			this.connections.add(to);
		}
	}
	
	public void AddConnection(Node conn){
		this.connections.add(conn);
	}
	
}

@@ -2001,539 +2001,8 @@
 %7D%0A%09%0A
-%09static Node FindNode(Node currNode, int value)%7B%0A%09    %0A%09    if(currNode.value == value)%7B%0A%09        return currNode;   %0A%09    %7D%0A%09    else if(currNode.connections.size() == 0)%7B%0A%09        return null;%0A%09    %7D%0A%09    %0A%09    if(visited%5BcurrNode.value%5D == 1)%7B%0A%09%09%09return null;%0A%09%09%7D%0A%09    visited%5BcurrNode.value%5D = 1;%0A%09    Node found = null;%0A%09    for(int i=0;i%3CcurrNode.connections.size();i++)%7B%0A%09        found = FindNode(currNode.connections.get(i), value);%0A%09        if(found != null)%7B%0A%09            break;%0A%09        %7D%0A%09    %7D%0A%09    return found;%0A%09%7D%0A%09%0A
 %7D%0A%0Ac

Update Solution.java