a, b, x, y = map(int, input().split())
i = 1
while (a > 0) or (b > 0):
    if (i % x != 0) and (a > 0):
        a = a - 1
    elif (i % y != 0) and (b > 0):
        b = b - 1
    i = i + 1
print(i - 1)