A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true:

  * Employee A is the immediate manager of employee B
  * Employee B has an immediate manager employee C such that employee A is the superior of employee C. 



The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.

Today the company is going to arrange a party. This involves dividing all n employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees A and B such that A is the superior of B.

What is the minimum number of groups that must be formed?

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of employees.

The next n lines contain the integers pi (1 ≤ pi ≤ n or pi = -1). Every pi denotes the immediate manager for the i-th employee. If pi is -1, that means that the i-th employee does not have an immediate manager. 

It is guaranteed, that no employee will be the immediate manager of him/herself (pi ≠ i). Also, there will be no managerial cycles.

Output

Print a single integer denoting the minimum number of groups that will be formed in the party.

Examples

Input

5
-1
1
2
1
-1


Output

3

Note

For the first example, three groups are sufficient, for example: 

  * Employee 1 
  * Employees 2 and 4 
  * Employees 3 and 5 
import java.util.*;

public class Main {
	
	static int max; //Guardará el nivel más profundo
	static int employees; //Cantidad de nodos

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		employees = scan.nextInt();
		
		//Listas de adyacencia
		ArrayList<ArrayList<Integer>> adj = new ArrayList<ArrayList<Integer>>();
		
		//Lista de nodos raices
		ArrayList<Integer> roots = new ArrayList<Integer>();
		
		//Creamos una lista de adyacencia vacía por cada nodo
		for (int i = 0; i < employees; i++) adj.add(new ArrayList<Integer>());
		
		//Obtenemos los datos
		for (int i = 0; i < employees; i++){
			int boss = scan.nextInt();
			
			//Si tiene jefe agrego el empleado actual a la lista del jefe
			if (boss != -1) {
				boss--; //Necesito restar uno porque trabajo con indice 0
				
				ArrayList<Integer> v = adj.get(boss);
				v.add(i);
				//v = ady.get(i); Estas lineas son para grafos no dirigidos
				//v.add(boss);
				
			} else { //Sino lo agrego a la lista de nodos raices
				roots.add(i);
			}
		}
		scan.close();
		
		//Empiezo la búsqueda del nivel más profundo
		max = 0;
		for (int i = 0; i < roots.size(); i++){
			//Para cada nodo raiz reiniciamos los niveles y los visitados
			Integer levels = 0;
			boolean[] visited = new boolean[employees]; 
			dfs(adj, roots.get(i), levels, visited);
		}
		
		//renderGraph(adj);
		System.out.println(max);
		
	}
	
	public static void dfs(ArrayList<ArrayList<Integer>> adj, Integer v, Integer levels, boolean[] visited){
		
		ArrayList<Integer> vertex = adj.get(v); //Obtenemos la lista de adyacentes del nodo
		visited[v] = true; //Marcamos nodo como visitado
		levels++; //Sumamos un nivel
		
		//Si llegamos a un nodo sin hijos, quiere decir que estamos en el ultimo nivel de esa rama
		//Preguntamos si el nivel actual es mayor al máximo hasta ahora
		if (vertex.size() == 0 && levels > max) { 
			max = levels; 
		} else { //Sino llamamos recursivamente a la función con el próximo nodo adyacente no visitado
			for (int i = 0; i < vertex.size(); i++){
				Integer next = vertex.get(i);
				if (visited[next] == false) {
					dfs(adj,next,levels,visited);
				}
			}
		}
	}
	
	//Función para mostrar el grafo
	public static void renderGraph(ArrayList<ArrayList<Integer>> adj){
		for (int i = 0; i < employees; i++){
			System.out.print(i+1);
			ArrayList<Integer> v = adj.get(i);
			for (int j = 0; j < v.size(); j++) {
				System.out.print("->"+(v.get(j)+1));
			}
			System.out.println("");
		}
	}
	
}
