cnt1,cnt2,x,y=map(int,input().split())
do=cnt1+cnt2
up= 10**12


def checker(mid):
    if mid - mid//x>=cnt1 and mid -abs(mid//y-cnt1)>=cnt2:
        return True
    return False

while (up>=do):
    mid=(up+do)//2
    if checker(mid):
        up=mid-1
        an=mid
    else:
        do=mid+1
print(an)