-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

main = print . solve . read =<< getLine

solve n = ans where
    ans = fst $ foldl h (0, 0) $ map g [1..n]
    g x = (x, f 0 x)
    f a 1 = a
    f a x = f (a + 1 - mod x 2) (div x 2)
    h a@(_, ac) v@(_, vc) = if ac > vc then a else v

