public static void main ( String [ ] args ) throws IOException {
  BufferedReader r = new BufferedReader ( new InputStreamReader ( System . in ) , 1 ) ;
  String s = r . readLine ( ) ;
  String [ ] sl = s . split ( "[\\s]+" ) ;
  long R = Long . parseLong ( sl [ 0 ] ) ;
  long B = Long . parseLong ( sl [ 1 ] ) ;
  s = r . readLine ( ) ;
  sl = s . split ( "[\\s]+" ) ;
  long x = Long . parseLong ( sl [ 0 ] ) ;
  long y = Long . parseLong ( sl [ 1 ] ) ;
  long rl = 0 ;
  long rr = Math . min ( R , B ) + 1 ;
  while ( rr - rl >= 2 ) {
    long rm = ( rl + rr ) / 2 ;
    if ( ( R - rm ) / ( x - 1 ) + ( B - rm ) / ( y - 1 ) < rm ) {
      rr = rm ;
    }
    else {
      rl = rm ;
    }
  }
  System . out . println ( rl ) ;
}

public static void main ( String [ ] args ) throws IOException { BufferedReader r = new BufferedReader ( new InputStreamReader ( System . in ) , 1 ) ; String s = r . readLine ( ) ; String [ ] sl = s . split ( " [ \\ s ] + " ) ; long R = Long . parseLong ( sl [ 0 ] ) ; long B = Long . parseLong ( sl [ 1 ] ) ; s = r . readLine ( ) ; sl = s . split ( " [ \\ s ] + " ) ; long x = Long . parseLong ( sl [ 0 ] ) ; long y = Long . parseLong ( sl [ 1 ] ) ; long rl = 0 ; long rr = Math . min ( R , B ) + 1 ; while ( rr - rl >= 2 ) { long rm = ( rl + rr ) / 2 ; if ( ( R - rm ) / ( x - 1 ) + ( B - rm ) / ( y - 1 ) < rm ) { rr = rm ; } else { rl = rm ; } } System . out . println ( rl ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))) (decimal_integer_literal))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))