s = raw_input().split()
a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])

c1 = 0
c2 = 0
i = a + b

while True:
  if ((a <= i - (i / x)) and (b <= i - (i / y))):
    break
  i += 1

print i + (i / (x * y))
