#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(aw, c); aw -= tmp; bw += tmp; aw += min(d, bw); cout << aw << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); input(); solve(); getchar(); }