# your code goes here
"""author : darksider"""

import sys

cnt1,cnt2,x,y = map(int,sys.stdin.readline().split())

t = cnt1/(x-1)
if (cnt1%(x-1) == 0 ):
	t1 = x*t - 1
else:
	t1 = x*t + (cnt1%(x-1))
	
t = cnt2/(y-1)
if (cnt2%(y-1) == 0 ):
	t2 = y*t - 1
else:
	t2 = y*t + (cnt2%(y-1))
	
print max(t1,t2)