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

i = 1
c = 0

while True:
  if i % (x * y) == 0:
    c += 1

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

print i + c
