local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end
local a, b = io.read("*n", "*n")
local c, d = io.read("*n", "*n")
a = math.abs(a - c)
b = math.abs(b - d)
local gcd = getgcd(a, b)
a, b = a // gcd, b // gcd
print(gcd * (a + b - 1))
