import Data.List (findIndices)

main :: IO ()
main = print . solve =<< readLn

solve :: Int -> Int
solve n = succ
        . head
        . findIndices (== maximum l)
        $ l where
      l = map count [1 .. n]

count :: Int -> Int
count x = pred
        . length
        . takeWhile fst
        . iterate (\(x, y) -> (x && even y, div y 2))
        $ (even x, x)