public static void main ( String [ ] args ) {
  Scanner in = new Scanner ( System . in ) ;
  long n = in . nextLong ( ) ;
  long m = in . nextLong ( ) ;
  long xc = in . nextLong ( ) ;
  long yc = in . nextLong ( ) ;
  long k = in . nextLong ( ) ;
  List < Pair > list = new ArrayList < > ( ) ;
  for ( int i = 0 ;
  i < k ;
  i ++ ) {
    int x = in . nextInt ( ) ;
    int y = in . nextInt ( ) ;
    Pair pair = new Pair ( x , y ) ;
    list . add ( pair ) ;
  }
  long ans = 0 ;
  for ( int i = 0 ;
  i < k ;
  i ++ ) {
    long dx = list . get ( i ) . dx ;
    long dy = list . get ( i ) . dy ;
    long temp1 = Integer . MAX_VALUE ;
    long temp2 = Integer . MAX_VALUE ;
    long min ;
    if ( dx != 0 ) {
      if ( dx > 0 ) temp1 = ( n - xc ) / dx ;
      else temp1 = ( xc % dx == 0 ) ? ( xc / Math . abs ( dx ) ) - 1 : xc / Math . abs ( dx ) ;
    }
    if ( dy != 0 ) {
      if ( dy > 0 ) temp2 = ( m - yc ) / dy ;
      else temp2 = ( yc % Math . abs ( dy ) == 0 ) ? ( yc / Math . abs ( dy ) ) - 1 : yc / Math . abs ( dy ) ;
    }
    min = Math . min ( temp1 , temp2 ) ;
    ans += min ;
    xc += min * dx ;
    yc += min * dy ;
  }
  System . out . println ( ans ) ;
  in . close ( ) ;
}

public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long n = in . nextLong ( ) ; long m = in . nextLong ( ) ; long xc = in . nextLong ( ) ; long yc = in . nextLong ( ) ; long k = in . nextLong ( ) ; List < Pair > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < k ; i ++ ) { int x = in . nextInt ( ) ; int y = in . nextInt ( ) ; Pair pair = new Pair ( x , y ) ; list . add ( pair ) ; } long ans = 0 ; for ( int i = 0 ; i < k ; i ++ ) { long dx = list . get ( i ) . dx ; long dy = list . get ( i ) . dy ; long temp1 = Integer . MAX_VALUE ; long temp2 = Integer . MAX_VALUE ; long min ; if ( dx != 0 ) { if ( dx > 0 ) temp1 = ( n - xc ) / dx ; else temp1 = ( xc % dx == 0 ) ? ( xc / Math . abs ( dx ) ) - 1 : xc / Math . abs ( dx ) ; } if ( dy != 0 ) { if ( dy > 0 ) temp2 = ( m - yc ) / dy ; else temp2 = ( yc % Math . abs ( dy ) == 0 ) ? ( yc / Math . abs ( dy ) ) - 1 : yc / Math . abs ( dy ) ; } min = Math . min ( temp1 , temp2 ) ; ans += min ; xc += min * dx ; yc += min * dy ; } System . out . println ( ans ) ; in . close ( ) ; }
(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: (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: (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)))) (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 (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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) field: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) field: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)))) alternative: (expression_statement (assignment_expression left: (identifier) right: (ternary_expression condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) consequence: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) right: (decimal_integer_literal)) alternative: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)))) alternative: (expression_statement (assignment_expression left: (identifier) right: (ternary_expression condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (decimal_integer_literal))) consequence: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) right: (decimal_integer_literal)) alternative: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))