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

def test(i):
	k = i//y
	#~ print "k=",k
	l = i//x 
	#~ print "l=",l
	m = i//(x*y) 
	#~ print "m=", m
	forone = k - m
	miss1 = max(0, c1-forone)
	#~ print "miss1 =", miss1 
	fortwo = l - m
	miss2 = max(0, c2-fortwo)
	#~ print "miss2 =", miss2 
	hoard = i-m-forone-fortwo
	#~ print "hoard=", hoard
	if miss1+miss2<=hoard:
		return True
	else:
		return False

start=c1+c2
per = x*y - x - y
antalper = (c1+c2)//per + 1
end = x*y*antalper

s1 = start
e1 = (start+end)//2

s2 = (start+end)//2 + 1
e2 = end

res = 1

if test(start):
	print start

while s2!=e2 and s1!=e1 and res!=0:
	if(test(e1)):
		s1 = s1
		e2 = e1
		e1 = (s1+e2)//2
		s2 = e1 + 1
	else:
		if(test(s2)):
			res = 0
			print s2
		else:
			s1 = s2
			e2 = e2
			e1 = (s1+e2)//2
			s2 = e1 + 1
			

if(res!=0):
	if(test(s1)):
		print s1
	elif(test(s1+1)):
		print s1+1
	else:
		print s1+2



