#include <bits/stdc++.h>
using namespace std ;
 
#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define pll             pair<ll,ll> 
#define ld              long double

ll c1, c2, x, y;

ll lcm(ll x, ll y){
    return (x*y)/(__gcd(x,y));
}

bool check(ll val){


    ll n1 = val/x, n2 = val/y; 
    ll comm = val/lcm(x,y);

    ll v1 = min(c1, n2 - comm), v2 = min(c2, n1 - comm); 
    ll rem = val - n1 - n2 + comm;

    if(rem < c1 - v1)
        return false;

    rem -= c1 - v1; 

    if(rem< c2 - v2)
        return false; 

    return true;
}

void Heavy_Gaurav_Singh(){
     
    cin>>c1>>c2>>x>>y; 

    ll l = 1, r = c1+c2+(c1/x)+(c2/y)+10; 
    ll ans; 

    while(l<=r){

        ll mid = (l+r)/2; 
        if(check(mid)){
            ans = mid; 
            r = mid-1; 
        }else
            l = mid + 1;

    }

    cout<<ans<<endl;
}


int main()
{ 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int test = 1; 
    //cin>>test;
    while(test--){
        Heavy_Gaurav_Singh(); 
    }

    return 0; 
}