cnt_1, cnt_2, x, y = map(int, input().split())


l = 0
r = 10**18
lcm = x*y
while r > l:
    mid = (l+r) // 2

    if mid - mid/x < cnt_1 or min(mid-cnt_1-mid//lcm, mid-mid++y) < cnt_2:
        l = mid + 1
    else:
        r = mid    

print(l)