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