#include #include #include #include #define REP(i, a, b) for (int i = int(a); i < int(b); i++) #define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl using namespace std; typedef long long int lli; const int mod = 1000000007; int main() { int Aw, Ab, Bw, Bb, C, D; cin >> Aw >> Ab >> Bw >> Bb >> C >> D; int tmp = max(C - Ab, 0); Aw -= tmp; Bw += tmp; cout << Aw + min(Bw, D) << endl; return 0; }