#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a, b, x, y;
int judge(__int64 pp){
    __int64 qq =  (pp - pp/x - pp/y + pp/(x*y));
    int cont1 = max(0, (int)(a-(pp/y-pp/(x*y))));
    int cont2 = max(0, (int)(b-(pp/x-pp/(x*y))));
    if(qq >= cont1+cont2)
        return 1;
    return 0;

}
__int64 solve(__int64 l, __int64 r){
    __int64 res;
    while(l <= r){
        __int64 mid = (l+r) / 2;
        if(judge(mid)){
            res = mid;
            r = mid - 1;
        }
        else
            l = mid + 1;
    }
    return res;
}
int main(){
    while(scanf("%d%d%d%d", &a, &b, &x, &y) == 4){
        __int64 temp = 1000000000;
        __int64 ans = solve(1, temp);
        printf("%I64d\n", ans);
    }
    return 0;
}
