public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  int h = sc . nextInt ( ) ;
  int w = sc . nextInt ( ) ;
  int n = sc . nextInt ( ) ;
  for ( int i = 0 ;
  i < w ;
  i ++ ) {
    if ( i >= heights . size ( ) ) {
      heights . add ( new TreeSet < Integer > ( ) ) ;
    }
    else {
      heights . get ( i ) . clear ( ) ;
    }
    heights . get ( i ) . add ( h ) ;
  }
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    int h_i = sc . nextInt ( ) ;
    int w_i = sc . nextInt ( ) ;
    h_i -= 1 ;
    w_i -= 1 ;
    heights . get ( w_i ) . add ( h_i ) ;
  }
  int current_h = 0 , current_w = 0 ;
  int ans = h ;
  while ( current_h < h && current_w < w ) {
    int hh = heights . get ( current_w ) . higher ( current_h ) ;
    ans = Math . min ( ans , hh ) ;
    current_h += 1 ;
    if ( heights . get ( current_w ) . contains ( current_h ) ) {
      break ;
    }
    if ( current_w + 1 >= w ) {
      break ;
    }
    if ( ! heights . get ( current_w + 1 ) . contains ( current_h ) ) {
      current_w += 1 ;
    }
  }
  System . out . println ( ans ) ;
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < w ; i ++ ) { if ( i >= heights . size ( ) ) { heights . add ( new TreeSet < Integer > ( ) ) ; } else { heights . get ( i ) . clear ( ) ; } heights . get ( i ) . add ( h ) ; } for ( int i = 0 ; i < n ; i ++ ) { int h_i = sc . nextInt ( ) ; int w_i = sc . nextInt ( ) ; h_i -= 1 ; w_i -= 1 ; heights . get ( w_i ) . add ( h_i ) ; } int current_h = 0 , current_w = 0 ; int ans = h ; while ( current_h < h && current_w < w ) { int hh = heights . get ( current_w ) . higher ( current_h ) ; ans = Math . min ( ans , hh ) ; current_h += 1 ; if ( heights . get ( current_w ) . contains ( current_h ) ) { break ; } if ( current_w + 1 >= w ) { break ; } if ( ! heights . get ( current_w + 1 ) . contains ( current_h ) ) { current_w += 1 ; } } System . out . println ( ans ) ; }
(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)))) (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 (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))))) alternative: (block (expression_statement (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (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 (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)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (identifier) right: (identifier)))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (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: (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (identifier)))) consequence: (block (break_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (identifier))) consequence: (block (break_statement))) (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))