import Data.Bits main = do n <- readLn :: IO Int putStrLn . show $ resolve n resolve :: Int -> Int resolve n = resolve' [1] [] [] 1 where resolve' [] [] _ _ = -1 resolve' [] nx sd c = resolve' nx [] sd (c + 1) resolve' (t:ts) nx sd c | t == n = c | t `elem` sd || t > n = resolve' ts nx sd c | otherwise = resolve' ts ((t + bitCnt t):(t - bitCnt t):nx) (t:sd) c bitCnt :: Int -> Int bitCnt 0 = 0 bitCnt n | n > 10000 || n == 0 = 0 | otherwise = 1 + bitCnt (n .&. (n - 1))