#include using namespace std; typedef long long ll; int main() { int a, aa, b, bb, c, d; cin>>a>>aa>>b>>bb>>c>>d; if (a >= c) { a -= c; b += c; } else { aa -= c - a; bb += c - a; b += a; a = 0; } cout << a + min(b, d) << endl; return 0; }