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

	xy = x*y
	cnt = cnt1+cnt2
	v = cnt
	vxy=int(v/xy)
	vx=int(v/x)
	vy=int(v/y)
	while not(v-vxy>=cnt and v>=cnt1+vx and v>=cnt2+vy):
		v = v + 1
	print(v)


if __name__ == '__main__':
	main()