#include <bits/stdc++.h>
using namespace std;
//1 2 3 4 5 6 7 8 9 10
//2 4 6 8 10--->1 3 5 7 9
//3 6 9---1 2 4 5 7 8 10
int main()
{
    long long int cnt1,cnt2,x,y;
    cin>>cnt1>>cnt2>>x>>y;
    long long int low=1,high=1000000000;
    long long ans=0;
    while(low<=high)
    {
        long long int mid=(low+high)/2;
        long long int g=mid/x;
      //  g=mid-g;
        long long int h=mid/y;
      //  h=mid-h;
        long long int r=(x*y);
        r=r/(__gcd(x,y));
        r=mid/r;
        long long cntt=cnt1;
        long long cnttt=cnt2;
        cntt-=g-r;
        cnttt-=h-r;
        long long lft=mid-g-h+r;
        if((cntt+cnttt)<=lft)
        {
            ans=mid;
            high=mid-1;
        }
        else
        {
            low=mid+1;
        }
    }
    cout<<ans<<endl;
}
