public static void main ( String [ ] args ) {
  String n = scanner . next ( ) ;
  System . out . println ( n . charAt ( 0 ) - 49 + ( n . length ( ) - 1 ) * 9 + ( n . substring ( 1 ) . matches ( "9*" ) ? 1 : 0 ) ) ;
}

public static void main ( String [ ] args ) { String n = scanner . next ( ) ; System . out . println ( n . charAt ( 0 ) - 49 + ( n . length ( ) - 1 ) * 9 + ( n . substring ( 1 ) . matches ( "9 * " ) ? 1 : 0 ) ) ; }
(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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (decimal_integer_literal)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) right: (decimal_integer_literal))) right: (parenthesized_expression (ternary_expression condition: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) name: (identifier) arguments: (argument_list (string_literal))) consequence: (decimal_integer_literal) alternative: (decimal_integer_literal)))))))))