function Main(input) {
  attack = (H) => {
    if (H === 1) {
      return 1;
    } else if (H % 2 === 1) {
      H--;
    }
    return attack(H / 2) * 2 + 1;
  }
  console.log(this.attack(Number(input.trim())))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));