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

for i in xrange(100):
    both = cur/x/y
    num1 = cur-cur/x-both
    num2 = cur-cur/y-both
    d1 = num1-cnt1
    d2 = num2-cnt2
    if d1 >= -both and d2 >= -both and d1+d2 >= both:
        upper = cur
    else:
        under = cur
    cur = (upper+under+1)/2
print cur