import math

def find(cnt1,cnt2,x,y):
	rs = cnt1 + cnt2
	while True:
		a = int(math.log(rs,x))
		b = int(math.log(rs,y))
		if rs - a - b < max(cnt1-b,0)+max(cnt2-a,0):
			rs += 1
		else:
			break
	return rs

#while True:
(cnt1,cnt2,x,y) = map(int,raw_input().split())
print find(cnt1,cnt2,x,y)
