{-# OPTIONS_GHC -Wno-tabs #-}
import Data.List (unfoldr, scanl1)

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

solve :: Integer -> Integer
solve n = (scanl1 (+) $ take 40 $ iterate (*2) 1) !! m
	where
    	m  = subtract 1 $ length $ f n

f :: Integer -> [Integer]
f = unfoldr g
	where
        g :: Integer -> Maybe (Integer, Integer)
        g 0 = Nothing
        g m = Just (m `mod` 2, m `div` 2)