[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
 
 #print result, for_n1, for_n2
 
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:
    #    print True
    result = result1
 #print result, for_n1, for_n2
result3 = (n1 + n2)*(x*y)/(x*y - 1)
if result3%(x*y) == 0:
    result3 -= 1
not_for_n1 = result3 - (result3/x - result3/(x*y))
not_for_n2 = result3 - (result3/y - result3/(x*y))
common = result3 - (result3/x + result3/y - result3/(x*y))
 #print (n1, n2), result3, (not_for_n1, not_for_n2), (x, y), result3 - not_for_n1, result3 - not_for_n2
if not_for_n1 > n2 and not_for_n2 > n1:
    #print not_for_n1, not_for_n2, common
    result = result3
print result