public static void main ( String ar [ ] ) {
  Scanner s = new Scanner ( System . in ) ;
  int w = s . nextInt ( ) ;
  int h = s . nextInt ( ) ;
  int w1 = s . nextInt ( ) ;
  int h1 = s . nextInt ( ) ;
  int w2 = s . nextInt ( ) ;
  int h2 = s . nextInt ( ) ;
  for ( int i = h ;
  i >= 0 ;
  i -- ) {
    w += i ;
    if ( h1 == i ) w = w - w1 ;
    else if ( h2 == i ) w = w - w2 ;
    if ( w < 0 ) w = 0 ;
  }
  System . out . println ( w ) ;
}

public static void main ( String ar [ ] ) { Scanner s = new Scanner ( System . in ) ; int w = s . nextInt ( ) ; int h = s . nextInt ( ) ; int w1 = s . nextInt ( ) ; int h1 = s . nextInt ( ) ; int w2 = s . nextInt ( ) ; int h2 = s . nextInt ( ) ; for ( int i = h ; i >= 0 ; i -- ) { w += i ; if ( h1 == i ) w = w - w1 ; else if ( h2 == i ) w = w - w2 ; if ( w < 0 ) w = 0 ; } System . out . println ( w ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) 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: (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: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (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))))))