p = raw_input()
d = p.split()
cnt1 = int(d[0])
cnt2 = int(d[1])
x = int(d[2])
y = int(d[3])
num = 1
while(cnt1 > 0 or cnt2 > 0):
    if(num % x != 0):
        cnt1 -= 1
    elif(num % y !=0):
        cnt2 -= 1
    num +=1
print num-1
