cnt1, cnt2, x, y = map(int, raw_input().split())
st = 1
rem = 0
rch = 0
while cnt1+cnt2>0:
    
    mul = x*y
    st = rch + 1
    rem = (st-1)%mul
    
    cnt = cnt1+cnt2+rem
    
    v = cnt - (cnt/mul)
    sv = cnt/mul
    xb = cnt/y - sv
    xa = cnt/x - sv
    
    rch += v
    
    if xb > cnt2:
        v -= xb - cnt2
    if xa > cnt1:
        v -= xa - cnt1
    
    
    v += (rem/mul) - rem
    xbr = rem/x - rem/mul
    xar = rem/y - rem/mul
    v += xbr + xar
    
    """
    cnt1 -= xa
    cnt2 -= xb
    
    if cnt1<0:
        cnt1 = 0
    if cnt2<0:
        cnt2 = 0
    """
    
    xa = min(cnt1,xa)
    xb = min(cnt2,xb)
    
    cnt1-=xa
    cnt2-=xb
    v-=(xa+xb)
    
    if v>0:
        cnt1-=v
        v-=cnt1
    if v>0:
        cnt2-=v

print rch
