import Data.List

main = print . solve . read =<< getLine

solve :: Int -> Int
solve x = solve' x 1 [0]

solve' x i ps
    | elem x ps = i - 1
    | otherwise = solve' x (i+1) . nub . sort $ (ps ++ map (subtract i) ps) ++ (map (+i) ps)
