inData = input().strip().split(" ")
c1,c2,x,y = int(inData[0]),int(inData[1]),int(inData[2]),int(inData[3])
arvud1 = []
count1 = c1
count2 = c2
limx = x
limy = y

if c2>c1:
    count1 = c2
    count2 = c1
    limx = y
    limy = x
n = 1
while (len(arvud1)<count1):
    if (n%limx!=0):
        arvud1.append(n)
    n+=1
k = 1


print(arvud1[-1])