'use strict'


function Main(input) {
  input = input.trim()
  const H = parseInt(input)

  let cc = 1
  const dfs = (n) => {
    if(n === 1) return
    const h = Math.floor(n/2)
    cc += h * 2
    dfs(h)
  }

  dfs(H, 0)

  console.log(cc)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));