c1, c2, x, y = map(int, raw_input().split())
more = 1
prevb = 0
preva = 0
ctot = c2 + c1
while (more>0):
    a = (ctot/y)- (ctot/(x*y))
    b = (ctot/x)- (ctot/(x*y))
    ab = ctot - a - b

    if a>c1:
        a = c1
    if b>c2:
        b = c2
    more = c1+c2 - a - b - ab
    ctot +=more
print ctot

