data = [int(g) for g in raw_input().split()]
c1 = data[0]
c2 = data[1]
x = data[2]
y = data[3]

i=c1+c2-1
k = i//y
#~ print "k=",k
l = i//x 
#~ print "l=",l
m = i//(x*y) 
#~ print "m=", m
forone = k - k//x
miss1 = max(0, c1-forone)
#~ print "miss1 =", miss1 
fortwo = l-l//y
miss2 = max(0, c2-fortwo)
#~ print "miss2 =", miss2 
hoard = i-m-forone-fortwo
#~ print "hoard=", hoard
res = 1

while res!=0:
	i+=1
	if (i % x != 0 and i % y != 0):
		hoard+=1
		#~ print "hoard=", hoard
	elif (i % x == 0 and miss2>0):
		miss2-=1
		#~ print "miss2 after=", miss2
	elif (i % y == 0 and miss1>0):
		miss1-=1
		#~ print "miss1 after=", miss1		
	if miss1+miss2<=hoard:
		res = 0

print i
	

