#include using namespace std; int main(){ int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f; if(b < e){ d += b; c += (e-b); a -= (e-b); b = 0; }else{ d += e; b -= e; } if(c < f){ cout << a+c << endl; }else{ cout << a+f << endl; } }