main :: IO ()
main = do
  [a, b, c, d] <- map read . words <$> getLine :: IO [Int]
  print $ solve (a, b) (c, d)

solve s@(a, b)  g@(c, d)
  | a == c = 0
  | b == d = 0
  | otherwise = x + y - gcd x y
  where
    x = abs $ a - c
    y = abs $ b - d
