cnt1, cnt2, x, y = map(int, input().split())

res = 1
a = 0
b = 0

res1 = 0
res2 = 0

if x-1 < cnt1:
    if cnt1 % (x-1):
        res1 = (cnt1 // (x-1)) * x + cnt1 % (x - 1)
    else:
        res1 = (cnt1 // (x-1)) * x - 1
else:
    res1 = cnt1

if y-1 < cnt2:
    if cnt2 % (y-1):
        res2 = (cnt2 // (y-1)) * y + cnt2 % (y - 1)
    else:
        res2 = (cnt2 // (y-1)) * y - 1
else:
    res2 = cnt2

if res1 > res2:
    step = res1 // x
    if res2 - step > 0:
        res = res1 + res2 - step
        if not res1 % y:
            res -= 1
    else:
        res = res1
elif res1 < res2:
    step = res2 // y
    if res1 - step > 0:
        res = res2 + res1 - step
        if not res2 % x:
            res -= 1
    else:
        res = res2
else:
    step1 = res1 // x
    step2 = res2 // y
    if step1 > step2:
        if res2 - step1 > 0:
            res = res1 + res2 - step1
            if not res1 % y:
                res -= 1
        else:
            res = res1
    else:
        if res1 - step2 > 0:
            res = res2 + res1 - step2
            if not res2 % x:
                res -= 1
        else:
            res = res2

print(res)