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