#include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; #define mod 1000000007 #define INF 1000000000 //(int)1e9 #define LLINF 2000000000000000000 //(ll)2e18 #define PI 3.1415926536 #define SIZE 100000 int main(){ int aw,ab,bw,bb,c,d; int s; cin >> aw >> ab >> bw >> bb >> c >> d; s = ab; aw-=max(0,c-s); bw+=max(0,c-s); ab-=min(c,s); bb+=min(c,s); s = bw; bb-=max(0,c-s); ab+=max(0,c-s); bw-=min(d,s); aw+=min(d,s); cout << aw << endl; return 0; }