from math import gcd

def check(n):
	global cnt1, cnt2, x, y
	xdiv = n//x
	ydiv = n//y
	xydiv = n//(x*y)

	xndiv = n-xdiv
	yndiv = n-ydiv
	xyndiv = n-xydiv

	xyndiv -= ydiv
	xyndiv -= xdiv
	yndiv -= xyndiv
	xndiv -= xyndiv

	if xndiv +xyndiv < cnt1:
		return 0
	xyndiv -= max(0, cnt1-xndiv)
	if yndiv + xyndiv < cnt2:
		return 0
	return 1


cnt1, cnt2, x, y = map(int, input().split())

s = 1
e = 10**20

while s <= e:
	mid = (s+e)//2

	if check(mid) == 1:
		ans = mid
		e = mid-1
	else:
		s = mid+1

print(ans)