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

##5 to friend 1,
##6 to friend 2
##5+6 =11?
##friend 1 doesn't like 2 (1,3,5,7,9,11) can't give total/2 rounded down
##friend 2 doesn't like 3
##how to modify? 

total = cnt1+cnt2
while cnt1 > total-total/x or cnt2 > total-total/y:
    total += 1
print total
