a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
c1=a[0]
c2=a[1]
x=a[2]
y=a[3]
i = a[0]+a[1]
while 1:
	if (c1 <= i - (c1+c2)//x and c2 <= i - (c1+c2)//y - c1 + c2//y) or (c2 <= i - (c1+c2)//y and c1 <= i - (c1+c2)//x - c2 + c1//x):
		print(i)
		exit()
	i+=1
