import Control.Applicative
 
main = do
  x <- readLn
  putStr . show $ f x 0 [0]
 
f x t ys 
  | elem x ys = t
  | otherwise = f x s zs
  where 
    s = t + 1
    zs = nib $ [(\u -> u + s), (\u -> u), (\u -> u - s)] <*> ys