[n1, n2, x, y] = raw_input("").split(" ")
n1 = int(n1)
n2 = int(n2)
x = int(x)
y = int(y)
if n1 < n2:
    x, y = y, x
    n1, n2 = n2, n1
for_n1 = n1*x/(x - 1)
if for_n1%x == 0:
    for_n1 -= 1
result = for_n1
for_n2 = for_n1/x - for_n1/x/y
if for_n2 < n2:
    result = (n2 - for_n2)*y/(y-1) + for_n1
    if (for_n1 + 1) % y == 0:
        result += 1
    if result % y == 0:
        result -= 1
 
n1, n2 = n2, n1
x, y = y, x

for_n1 = n1*x/(x - 1)
if for_n1%x == 0:
    for_n1 -= 1
result1 = for_n1
for_n2 = for_n1/x - for_n1/x/y
if for_n2 < n2:
    result1 = (n2 - for_n2)*y/(y-1) + for_n1
    if (for_n1 + 1) % y == 0:
        result1 += 1
    if result1 % y == 0:
        result1 -= 1
if result1 < result:
    result = result1
print result