#include using namespace std; int main(void){ long long A,B,N,M,sa,mc;cin >> A >> B >> N >> M; if(B>A){ sa=B-A; mc=A; for(;;){ if(sa>M){ sa=sa-M; mc++; }else{ break; } } cout << mc << endl; return 0; }else if(A>B){ sa=A-B; mc=B; for(;;){ if(sa>N){ sa=sa-N; mc++; }else{ break; } } cout << mc << endl; return 0; } }