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

if cnt1<cnt2:
    cnt1,cnt2=cnt2,cnt1
    x,y=y,x

pans,ans = 0,cnt1
while ans//x - pans//x > 0:
    pans,ans = ans,ans+(ans//x - pans//x)

cnt2=max(cnt2-ans//x+ans//(x*y),0)
pans,ans = ans,ans+cnt2

while ans//x - pans//x > 0:
    pans,ans = ans,ans+(ans//x - pans//x)

print(ans)