import sys,math

if __name__ == '__main__':
	[c1,c2,x,y] = map(int,raw_input().split())
	a,b = set(),set()
	for i in range(1,1000000):
		if i % x != 0:
			a.add(i)
		if i % y != 0:
			b.add(i)
		# they first need to have reached the minimum
		if len(a) >= c1 and len(b) >= c2:
			inter = a & b
			a_i,b_i = a-inter,b-inter
			a_need = c1 - len(a_i)
			b_need = c2 - len(b_i)
			if ( len(inter) >= a_need + b_need ):
				print i
				exit(0)
	
