function main(input) {
  var H = input[0]-0;
  console.log(calc(H));
}


var map = {1:1};
function calc(H){
  if(map[H]) return map[H];
  return map[H] = (calc(Math.floor(H/2))+calc(Math.floor(H/2))+1);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').split("\n"))
