main :: IO ()
main = interact $ format . solve . parse

parse :: String -> Int
parse = read . head . lines

solve :: Int -> Int
solve 1 = 1
solve n = 1 + 2 * solve (n `div` 2)

format :: Int -> String
format = (++ "\n") . show
