#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; ll Aw, Ab, Bw, Bb, C, D; int main() { cin >> Aw >> Ab >> Bw >> Bb >> C >> D; if (Ab < C) Aw -= C - Ab, Bw += C - Ab; Aw += min(Bw, D); cout << Aw << endl; return 0; }