cnt1, cnt2, x, y = raw_input().split()

if int(cnt1) >= 1 and int(cnt1) < 10**9 and int(cnt2) >= 1 and int(cnt2) < 10**9 and int(cnt1) + int(cnt2) <= 10**9 and int(x) < int(y) and int(x) >= 2 and int(y) <= 3*(10**4):

	maximum = 1
	presents = 0
	num = 1
	while presents < int(cnt1):
		if num % int(x) != 0:
			maximum = num
			presents += 1
		num += 1

	maximum2 = 1
	presents = 0
	num = 1
	while presents < int(cnt2):
	        if num <= maximum and num % int(x) != 0:
			 pass
		elif num % int(y) != 0:
	                maximum2 = num
			presents += 1
	        num += 1

	print max(maximum,maximum2)
