def check(v):
    fa = v - v // x
    fb = v - v // y
    return (fa >= a) and (fb >= b)

a, b, x, y = map(int, input().split())
l, r = 0, (a + b) * 2
while l <= r:
    mid = (l + r) // 2
    if check(mid):
        ans = mid
        r = mid - 1
    else:
        l = mid + 1
print(ans)

