function Main(input) {
    var H = parseInt(input[0], 10);
    var result = 0;
    var count = 0;

    while(H !== 0) {
        result += Math.pow(2, count);
        H = Math.floor(H / 2);
        count ++;
    }

    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));