#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 - (c - ab); bw += c - ab; ans += min(bw, d); cout << ans << endl; return 0; }