public static void solve ( InputReader in , PrintWriter out ) {
  int n = in . nextInt ( ) ;
  int m = in . nextInt ( ) ;
  int div2 = 1 , div1 = n ;
  int a , b ;
  for ( int i = 0 ;
  i < m ;
  i ++ ) {
    a = in . nextInt ( ) ;
    b = in . nextInt ( ) ;
    div2 = Math . max ( div2 , Math . min ( a , b ) ) ;
    div1 = Math . min ( div1 , Math . max ( a , b ) ) ;
  }
  if ( div1 - div2 >= 0 ) out . print ( div1 - div2 ) ;
  else out . print ( "0" ) ;
}

public static void solve ( InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int div2 = 1 , div1 = n ; int a , b ; for ( int i = 0 ; i < m ; i ++ ) { a = in . nextInt ( ) ; b = in . nextInt ( ) ; div2 = Math . max ( div2 , Math . min ( a , b ) ) ; div1 = Math . min ( div1 , Math . max ( a , b ) ) ; } if ( div1 - div2 >= 0 ) out . print ( div1 - div2 ) ; else out . print ( "0" ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (type_identifier) name: (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: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (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 (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)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier))))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal)))))))