import qualified Data.IntMap.Strict as M
import Data.Foldable
 
favo 1 = M.singleton 1 0
favo n
  | odd n = M.insert n 0 f
  | even n = M.insert n v f
    where
    f = favo $ n - 1
    v = f M.! (n `div` 2) + 1
 
findKeyAtMax = fst . foldr1 f . M.toList
  where
  f (k, v) (j, u)
    | v > u = (k, v)
    | otherwise = (j, u)
 
main = do
  n <- readLn
  print . findKeyAtMax $ favo n