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


def ret(num):
    take1=num-num/x
    take2=num-num/y
    take_both=(take1+take2-num/x-num/y)/2
    
    return (take1>=cnt1 and take2>=cnt2 and take1+take2-take_both>=cnt1+cnt2)



begs=1
ends=1000000000**2

while(begs<ends):
    mid=(begs+ends)/2

    if(ret(mid)):
        ends=mid
    
    else:
        begs=mid+1


    print ends
