public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  int k = sc . nextInt ( ) ;
  int [ ] dist = new int [ k ] ;
  for ( int i = 0 ;
  i < k ;
  i ++ ) {
    dist [ i ] = Integer . MAX_VALUE ;
  }
  dist [ 1 ] = 0 ;
  Deque < Integer > deque = new ArrayDeque < > ( ) ;
  deque . addFirst ( 1 ) ;
  int [ ] visit = new int [ k ] ;
  visit [ 1 ] = 1 ;
  while ( deque . size ( ) > 0 ) {
    int u = deque . pollFirst ( ) ;
    int v1 = ( 10 * u ) % k ;
    int v2 = ( u + 1 ) % k ;
    if ( visit [ v1 ] == 0 ) {
      dist [ v1 ] = Math . min ( dist [ v1 ] , dist [ u ] ) ;
      deque . addFirst ( v1 ) ;
      visit [ v1 ] = 1 ;
    }
    else {
      if ( dist [ v1 ] > dist [ u ] ) {
        dist [ v1 ] = dist [ u ] ;
        deque . remove ( v1 ) ;
        deque . addFirst ( v1 ) ;
      }
    }
    if ( visit [ v2 ] == 0 ) {
      dist [ v2 ] = Math . min ( dist [ v2 ] , dist [ u ] + 1 ) ;
      deque . addLast ( v2 ) ;
      visit [ v2 ] = 1 ;
    }
  }
  System . out . println ( dist [ 0 ] + 1 ) ;
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int [ ] dist = new int [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { dist [ i ] = Integer . MAX_VALUE ; } dist [ 1 ] = 0 ; Deque < Integer > deque = new ArrayDeque < > ( ) ; deque . addFirst ( 1 ) ; int [ ] visit = new int [ k ] ; visit [ 1 ] = 1 ; while ( deque . size ( ) > 0 ) { int u = deque . pollFirst ( ) ; int v1 = ( 10 * u ) % k ; int v2 = ( u + 1 ) % k ; if ( visit [ v1 ] == 0 ) { dist [ v1 ] = Math . min ( dist [ v1 ] , dist [ u ] ) ; deque . addFirst ( v1 ) ; visit [ v1 ] = 1 ; } else { if ( dist [ v1 ] > dist [ u ] ) { dist [ v1 ] = dist [ u ] ; deque . remove ( v1 ) ; deque . addFirst ( v1 ) ; } } if ( visit [ v2 ] == 0 ) { dist [ v2 ] = Math . min ( dist [ v2 ] , dist [ u ] + 1 ) ; deque . addLast ( v2 ) ; visit [ v2 ] = 1 ; } } System . out . println ( dist [ 0 ] + 1 ) ; }
(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: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (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))))) (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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (field_access object: (identifier) field: (identifier)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) (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))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) 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: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (array_access array: (identifier) index: (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal)))))))