#include #include typedef long long ll; int main(void) { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(13); ll aw, ab, bw, bb, c, d; std::cin >> aw >> ab >> bw >> bb >> c >> d; ll mw, mb; mb = std::min(c, ab); mw = c - mb; aw -= mw; ab -= mb; bw += mw; bb += mb; mw = std::min(d, bw); std::cout << aw + mw << std::endl; return 0; }