#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int aw, ab, bw, bb, c, d; cin >> aw >> ab >> bw >> bb >> c >> d; int ans = aw - max(0, c - ab); bw += max(0, c - ab); ans += min(bw, d); cout << ans << endl; return 0; }