#include #include using namespace std; int main(){ int aw,ab; int bw,bb; int c,d; cin >> aw >> ab >> bw >> bb >> c >> d; cout << aw - max(0,c-ab) + min(d,bw+max(0,c-ab)) << endl; return 0; }