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:
            return m
        if m-m/x < c1 or m-m/y < c2 or m-m/x/y < c1+c2:
            l = m+1
        else:
            h = m-1
    return h

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