import math

def findr(x,cnt):
	rs = cnt
	while True:
		if rs-int(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)
#print a,b
r = a+b
l = max(a,b)

print max(l,cnt1+cnt2)
