import math
import sys
import itertools
import fractions
if __name__ == '__main__':
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
w,h = map(int, wtf[0].split())
u1,d1 = map(int, wtf[1].split())
u2,d2 = map(int, wtf[2].split())
for i in range(h,-1,-1):
w+=i
if d1 == i:
w-=u1
if d2 == i:
w-=u2
if w < 0:
w=0
print(0 if w < 0 else w)
#include <iostream>
#include <array>
#include <algorithm>
void solve()
{
int w, h;
std::cin >> w >> h;
std::array<std::pair<int, int>, 2> stones;
for(auto& e : stones)
std::cin >> e.first >> e.second;
for(int i = h; i > 0; --i)
{
w += i;
for(const auto stone : stones)
if(stone.second == i)
w = std::max(0, w - stone.first);
}
std::cout << w << '\n';
}
int main()
{
solve();
return EXIT_SUCCESS;
}
1666L - Labyrinth | 1294B - Collecting Packages |
1642B - Power Walking | 1424M - Ancient Language |
600C - Make Palindrome | 1669D - Colorful Stamp |
1669B - Triple | 1669A - Division |
1669H - Maximal AND | 1669E - 2-Letter Strings |
483A - Counterexample | 3C - Tic-tac-toe |
1669F - Eating Candies | 1323B - Count Subrectangles |
991C - Candies | 1463A - Dungeon |
1671D - Insert a Progression | 1671A - String Building |
1671B - Consecutive Points Segment | 1671C - Dolce Vita |
1669G - Fall Down | 4D - Mysterious Present |
1316B - String Modification | 1204A - BowWow and the Timetable |
508B - Anton and currency you all know | 1672A - Log Chopping |
300A - Array | 48D - Permutations |
677C - Vanya and Label | 1583B - Omkar and Heavenly Tree |