def solve(c1, c2, x, y):
    l, h = 0, 10**9
    while l < h:
        m = l+(h-l)/2
        if m-m/x >= c1 and m-m/y >= c2 and m-m/x/y >= c1+c2:
            h = m
        else:
            l = m+1
    return h

c1, c2, x, y = map(int, raw_input().split())
print solve(c1, c2, x, y)
