#include <bits/stdc++.h>

using namespace std;

int x, y, cnt1, cnt2, lcm;

bool check(int input){
    int yo = input;
    int b1 = 0, b2 = 0;
    b1 += input / y;
    b2 += input / x;
    input -= yo / y;
    input -= yo / x;
    input += yo / lcm;
    if(cnt1 - b1 <= input)
        b1 += max(cnt1 - b1, 0), input -= max(cnt1 - b1, 0);
    else
        return 0;
    b2 += input;
    if(cnt1 <= b1 && cnt2 <= b2)
        return 1;
    else
        return 0;
}

int main()
{
    cin >> cnt1 >> cnt2 >> x >> y;
    lcm = (x * y) / __gcd(x, y);
    int lo = 2, hi = 1000 * 1000 * 1000;
    int mid;
    while(lo < hi - 1){
        mid = (hi + lo) / 2;
        if(check(mid))
            hi = mid;
        else
            lo = mid;
    }
    if(check(lo))
        cout << lo;
    else
        cout << hi;
    return 0;
}
