def solve(c1, c2, x, y):
    return max(solve1(c1, x), solve1(c2, y))

def solve1(c, x):
    l, h = 1, 10**9
    while l <= h:
        m = l+(h-l)/2
        t = m-m/x
        if t == c:
            return m
        if t < c:
            l = m+1
        else:
            h = m-1
    return h

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