public static void main ( String [ ] $ ) {
  Scanner sc = new Scanner ( in ) ;
  int a = sc . nextInt ( ) ;
  int b = sc . nextInt ( ) ;
  Queue < Integer > q = new ArrayDeque < > ( ) ;
  Queue < Integer > ans = new ArrayDeque < > ( ) ;
  q . add ( a ) ;
  ans . add ( 0 ) ;
  int answer = 10 ;
  while ( ! q . isEmpty ( ) ) {
    int p = q . poll ( ) ;
    int c = ans . poll ( ) ;
    if ( p == b ) {
      answer = c ;
      break ;
    }
    else {
      q . add ( ( p + 1 ) % 10 ) ;
      q . add ( ( p - 1 + 10 ) % 10 ) ;
      ans . add ( c + 1 ) ;
      ans . add ( c + 1 ) ;
    }
  }
  out . println ( answer ) ;
}

public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; Queue < Integer > q = new ArrayDeque < > ( ) ; Queue < Integer > ans = new ArrayDeque < > ( ) ; q . add ( a ) ; ans . add ( 0 ) ; int answer = 10 ; while ( ! q . isEmpty ( ) ) { int p = q . poll ( ) ; int c = ans . poll ( ) ; if ( p == b ) { answer = c ; break ; } else { q . add ( ( p + 1 ) % 10 ) ; q . add ( ( p - 1 + 10 ) % 10 ) ; ans . add ( c + 1 ) ; ans . add ( c + 1 ) ; } } out . println ( answer ) ; }
(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 (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: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (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)))) (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 (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) 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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (break_statement)) alternative: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) right: (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal))))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))