import sys
numbers = sys.stdin.readline().split()
cnt1 = int(numbers[0]) 
cnt2 = int(numbers[1])
x = int(numbers[2])
y = int(numbers[3])

lo = cnt1+cnt2
hi = 10**10
##total - big

mid = (lo+hi)/2
while hi > lo+1:
    
    if cnt1 > mid - mid/x or cnt2 > mid - mid/y:
        lo = mid
    else:
        hi = mid
    mid = (lo+hi)/2

def toosmall(mid):
    if cnt1 > mid - mid/x or cnt2 > mid - mid/y:
        return 1
    else:
        return 0

count= toosmall(mid-1)+toosmall(mid)+toosmall(mid+1)

print hi+count-2


