public static void solve ( ) {
  int n = s . nextInt ( ) - 1 ;
  ArrayList < Integer > list = new ArrayList < > ( ) ;
  int p = s . nextInt ( ) ;
  int q = s . nextInt ( ) ;
  for ( int i = p ;
  i < q ;
  i ++ ) {
    list . add ( i ) ;
  }
  while ( n -- > 0 ) {
    int a = s . nextInt ( ) ;
    int b = s . nextInt ( ) ;
    for ( int i = a ;
    i < b ;
    i ++ ) {
      if ( list . contains ( i ) ) list . remove ( new Integer ( i ) ) ;
    }
  }
  System . out . println ( list . size ( ) ) ;
}

public static void solve ( ) { int n = s . nextInt ( ) - 1 ; ArrayList < Integer > list = new ArrayList < > ( ) ; int p = s . nextInt ( ) ; int q = s . nextInt ( ) ; for ( int i = p ; i < q ; i ++ ) { list . add ( i ) ; } while ( n -- > 0 ) { int a = s . nextInt ( ) ; int b = s . nextInt ( ) ; for ( int i = a ; i < b ; i ++ ) { if ( list . contains ( i ) ) list . remove ( new Integer ( i ) ) ; } } System . out . println ( list . size ( ) ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) (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)))) (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: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (while_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) right: (decimal_integer_literal))) 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)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier))))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))