import math

def findr(x,cnt):
	rs = cnt
	while True:
		if rs-math.floor(math.log(rs,x)) < cnt:
			rs += 1
		else:
			break
	return rs

(cnt1,cnt2,x,y) = map(int,raw_input().split())
a = findr(x,cnt1)
b = findr(y,cnt2)
r = a+b
l = max(a,b)
ans = r

while l <= r:
#print (l,r)
	mid = (l+r)/2

	a = math.floor(math.log(mid,x))
	b = math.floor(math.log(mid,y))
	
	choose_a = cnt1-b
	choose_b = cnt2-a

	if cnt1-b <= mid-b-a and cnt2-a <= mid-b-a:
		if ans > mid:
			ans = mid
		r = mid-1
	else:
		l = mid+1
	
print ans
