import qualified Data.IntSet as S

main = do
    x <- readLn
    print $ solve x 0 (S.singleton 0)

solve :: Int -> Int -> S.IntSet -> Int
solve x i ns =
    let i' = i + 1
        ns' = S.fromList $ S.foldr (\n a -> [n+i',n,n-i'] ++ a) [] ns
    in if x `S.member` ns' then i' else solve x i' ns'
