import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (h : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print . f $ h

f :: Int -> Int
f 1 = 1
f h = 1 + 2 * f (h `div` 2)

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
