__author__ = 'Moustapha Saad'
cnt1, cnt2, x, y = map(int, raw_input().split())

def pd(cnt1, cnt2, x, y, acc):
    if cnt1 <= 0 and cnt2 <= 0:
        return acc-1
    if cnt1>0 and cnt2>0:
        if acc%x != 0 and acc%y != 0:
            return min(pd(cnt1-1,cnt2,x,y,acc+1),pd(cnt1,cnt2-1,x,y,acc+1))
        elif acc%x != 0:
            return pd(cnt1-1,cnt2,x,y,acc+1)
        elif acc%y != 0:
            return pd(cnt1,cnt2-1,x,y,acc+1)
    elif cnt1>0:
        if acc%x != 0:
            return pd(cnt1-1,cnt2,x,y,acc+1)
        else:
            return pd(cnt1,cnt2,x,y,acc+1)
    else:
        if acc%y != 0:
            return pd(cnt1,cnt2-1,x,y,acc+1)
        else:
            return pd(cnt1,cnt2,x,y,acc+1)
print pd(cnt1,cnt2,x,y,1)
