public static void main ( String [ ] $ ) {
  int n = s . nextInt ( ) ;
  int [ ] branches = new int [ n ] ;
  int [ ] parent = new int [ n ] ;
  int [ ] [ ] childlen = new int [ n ] [ ] ;
  for ( int i = 1 ;
  i < n ;
  ++ i ) ++ branches [ parent [ i ] = s . nextInt ( ) - 1 ] ;
  for ( int i = 0 ;
  i < n ;
  ++ i ) childlen [ i ] = new int [ branches [ i ] ] ;
  loop : for ( int i = 0 ;
  i < n ;
  ++ i ) {
    int I = i ;
    while ( true ) {
      if ( branches [ I ] > 0 ) break ;
      int r = 0 ;
      {
        int [ ] c = childlen [ I ] ;
        Arrays . sort ( c ) ;
        for ( int j = 0 , e = c . length ;
        j < e ;
        ++ j ) r = Math . max ( r , c [ j ] + e - j ) ;
      }
      if ( I == 0 ) {
        System . out . println ( r ) ;
        break loop ;
      }
      I = parent [ I ] ;
      childlen [ I ] [ -- branches [ I ] ] = r ;
    }
  }
}

public static void main ( String [ ] $ ) { int n = s . nextInt ( ) ; int [ ] branches = new int [ n ] ; int [ ] parent = new int [ n ] ; int [ ] [ ] childlen = new int [ n ] [ ] ; for ( int i = 1 ; i < n ; ++ i ) ++ branches [ parent [ i ] = s . nextInt ( ) - 1 ] ; for ( int i = 0 ; i < n ; ++ i ) childlen [ i ] = new int [ branches [ i ] ] ; loop : for ( int i = 0 ; i < n ; ++ i ) { int I = i ; while ( true ) { if ( branches [ I ] > 0 ) break ; int r = 0 ; { int [ ] c = childlen [ I ] ; Arrays . sort ( c ) ; for ( int j = 0 , e = c . length ; j < e ; ++ j ) r = Math . max ( r , c [ j ] + e - j ) ; } if ( I == 0 ) { System . out . println ( r ) ; break loop ; } I = parent [ I ] ; childlen [ I ] [ -- branches [ I ] ] = r ; } } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (update_expression (array_access array: (identifier) index: (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (array_access array: (identifier) index: (identifier))))))) (labeled_statement (identifier) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (while_statement condition: (parenthesized_expression (true)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (break_statement)) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)) right: (identifier)))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) (break_statement (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (update_expression (array_access array: (identifier) index: (identifier)))) right: (identifier))))))))))