public static void main ( String [ ] args ) {
  Scanner in = new Scanner ( System . in ) ;
  int n = in . nextInt ( ) ;
  int m = in . nextInt ( ) ;
  Set < Integer > numberSet = new HashSet < Integer > ( ) ;
  Queue < Pair > q = new LinkedList < Pair > ( ) ;
  q . add ( new Pair ( n , 0 ) ) ;
  while ( ! q . isEmpty ( ) ) {
    Pair current = q . remove ( ) ;
    if ( current . data == m ) {
      System . out . println ( current . level ) ;
      return ;
    }
    int newDouble = current . data * 2 ;
    int newLess = current . data - 1 ;
    if ( ! numberSet . contains ( newDouble ) ) {
      if ( current . data <= m ) {
        q . add ( new Pair ( newDouble , current . level + 1 ) ) ;
        numberSet . add ( newDouble ) ;
      }
    }
    if ( ! numberSet . contains ( newLess ) ) {
      q . add ( new Pair ( newLess , current . level + 1 ) ) ;
      numberSet . add ( newLess ) ;
    }
  }
  return ;
}

public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; Set < Integer > numberSet = new HashSet < Integer > ( ) ; Queue < Pair > q = new LinkedList < Pair > ( ) ; q . add ( new Pair ( n , 0 ) ) ; while ( ! q . isEmpty ( ) ) { Pair current = q . remove ( ) ; if ( current . data == m ) { System . out . println ( current . level ) ; return ; } int newDouble = current . data * 2 ; int newLess = current . data - 1 ; if ( ! numberSet . contains ( newDouble ) ) { if ( current . data <= m ) { q . add ( new Pair ( newDouble , current . level + 1 ) ) ; numberSet . add ( newDouble ) ; } } if ( ! numberSet . contains ( newLess ) ) { q . add ( new Pair ( newLess , current . level + 1 ) ) ; numberSet . add ( newLess ) ; } } return ; }
(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: (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 (type_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 (type_identifier))) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier) (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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier))))) (return_statement))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier) (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier) (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (return_statement)))