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

import sys

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

if ( cnt1%(x-1) == 0 ):
	t1 = ((cnt1*x)/(x-1))-1;

else:
	t1 = ((cnt1*x)/(x-1))+(cnt1%(x-1))

if ( cnt2%(y-1) == 0 ):
	t2 = ((cnt2*y)/(y-1))-1

else:
	t2 = ((cnt2*y)/(y-1))+(cnt2%(y-1))
	print max(t1,t2)