cnt1,cnt2,x,y = map(int,raw_input().split())
under,cur,upper = 1,10**9,10**18

for i in xrange(100):
    num = cur-cur/x-cur/y+cur/(x*y)
    if num >= cnt1+cnt2:
        upper = cur
    else:
        under = cur
    cur = (upper+under+1)/2
print cur