A, B, a, b = map(int, input().split(' '))

x = 0
while True:
  if x % A == a and x % B == b:
    break
  x += 1
  if x > A*B:
    x = 0
    break

print(x)