function Main(input) {
  var sum = 0;
  var last = 1;
  while(input!=1){
    input = Math.floor(input/2);
    sum += last;
    last*=2
  }
  sum+=last
  console.log(sum)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
