#include<bits\stdc++.h>
using namespace std;


long long binc(long long mn,long long mx,long long n1,long long p1,long long n2,long long p2,long long rem){
long long t,r1,rm;

    t=(mn+mx)/2;

    //if (t%p1==0)t--;

    r1=t/(p1*p2);

    rm=t-r1;
    cout<<t<<"  "<<rm<<endl;

    if(rm==n1+n2) { cout<<t;}

    if(n1+n2<rm)binc(mn,t,n1,p1,n2,p2,rem);
    if(n1+n2>rm){binc(t,mx,n1,p1,n2,p2,rem);}



}





int main()
{
    long long n1,n2,p1,p2,mx;
    cin >> n1>>n2 ;//>> n2 >> p1 >> p2;
    cin>>p1>>p2;
 if(n1*n2<p1*p2&&n2!=1){cout<<n1+n2;return 0;}
long long ntemp1=n1/p1;
long long ntemp2=n2/p2;
mx=n1*p1/(p1-1)+n2*p2/(p2-1);
long double t_;
long long t,r1,rm;
if(ntemp1>=ntemp2)
{
    t=n1*p1/(p1-1);
    if (t%p1==0)t--;

    r1=t/(p1*p2);


    rm=n2-(t/p1)+r1;
  //  cout<<rm;
  if(rm<=0){cout<<t;return 0;}
 else  binc(t,mx,n1,p1,n2,p2,rm);
}
else
{

     t=n2*p2/(p2-1);
     if(t%p2==0)t--;

    r1=t/(p1*p2);
    rm=n1-(t/p2)+r1;


 if(rm<=0){cout<<t;return 0;}
 else
    binc(t,mx,n2,p2,n1,p1,rm);
}

}

