#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main(void) { int aw, ab, bw, bb, c, d; cin >> aw >> ab; cin >> bw >> bb; cin >> c >> d; { int tmp = min(c, ab); aw -= c-tmp; bw += c-tmp; bb += tmp; } { int tmp = min(d, bw); aw += tmp; } cout << aw << endl; return 0; }