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