public static void main ( String [ ] args ) {
  Scanner scanner = new Scanner ( System . in ) ;
  int N = scanner . nextInt ( ) ;
  Box [ ] boxes = new Box [ N ] ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) boxes [ i ] = new Box ( scanner . nextInt ( ) , scanner . nextInt ( ) ) ;
  Arrays . sort ( boxes , ( b1 , b2 ) -> {
    if ( b1 . w != b2 . w ) return b1 . w - b2 . w ;
    return b2 . h - b1 . h ;
  }
  ) ;
  int [ ] dp = new int [ N ] ;
  int INF = 1_000_000 ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) dp [ i ] = INF ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    int j = lowerBound ( dp , boxes [ i ] . h ) ;
    if ( j == 0 || dp [ j - 1 ] < boxes [ i ] . h ) dp [ j ] = boxes [ i ] . h ;
  }
  int max = 0 ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) if ( dp [ i ] < INF ) max = Math . max ( max , i + 1 ) ;
  System . out . println ( max ) ;
}

public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; Box [ ] boxes = new Box [ N ] ; for ( int i = 0 ; i < N ; i ++ ) boxes [ i ] = new Box ( scanner . nextInt ( ) , scanner . nextInt ( ) ) ; Arrays . sort ( boxes , ( b1 , b2 ) -> { if ( b1 . w != b2 . w ) return b1 . w - b2 . w ; return b2 . h - b1 . h ; } ) ; int [ ] dp = new int [ N ] ; int INF = 1_000_000 ; for ( int i = 0 ; i < N ; i ++ ) dp [ i ] = INF ; for ( int i = 0 ; i < N ; i ++ ) { int j = lowerBound ( dp , boxes [ i ] . h ) ; if ( j == 0 || dp [ j - 1 ] < boxes [ i ] . h ) dp [ j ] = boxes [ i ] . h ; } int max = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( dp [ i ] < INF ) max = Math . max ( max , i + 1 ) ; System . out . println ( max ) ; }
(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: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (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: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (lambda_expression parameters: (inferred_parameters (identifier) (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (field_access object: (identifier) field: (identifier)))) consequence: (return_statement (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (field_access object: (identifier) field: (identifier))))) (return_statement (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (field_access object: (identifier) field: (identifier))))))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (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: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (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 name: (identifier) arguments: (argument_list (identifier) (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier))))) consequence: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (field_access object: (array_access array: (identifier) index: (identifier)) field: (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: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))