#include <bits/stdc++.h>
#define pb push_back
#define inf 0x3f3f3f3f
#define all(v) (v).begin() , (v).end()
#define ones(n) __builtin_popcount(n)
using namespace std;

typedef vector<int> vi;
typedef long long ll;

int di[] = {0 , 0 , 1 , -1 , 1 , 1 , -1 , -1};
int dj[] = {1 ,-1 , 0 , 0 , -1 , 1 ,  1 , -1};

ll cnt1 , cnt2 , x , y;
ll lcm;
bool valid(ll num){
    ll all = num - num / lcm;
    ll first = num - num / x;
    ll second = num - num / y;
    ll justSecond = all - first;
    ll Union = second - justSecond;
    ll justFirst = first - Union;
    ll leftF = max(0ll , cnt1 - justFirst);
    ll leftS = max(0ll , cnt2 - justSecond);
    return Union >= leftF + leftS;
}
int main(){
    cin >> cnt1 >> cnt2 >> x >> y;
    lcm = x * y / __gcd(x , y);
    ll l = 0 , r =  1000 , ans = -1;
    while(l <= r){
        ll mid = (l + r) / 2;
        if(valid(mid)){
            ans = mid;
            r = mid-1;
        }else
            l = mid+1;
    }

    cout << ans;
}
