process.stdin.resume();
process.stdin.setEncoding('utf8');

const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

reader.on('line', s => {
  let h = BigInt(s);
  let n = 0n;

  while (h !== 1n) {
    h /= 2n;
    n += 1n;
  }

  console.log(`${2n ** (n + 1n) - 1n}`.replace('n', ''));

  process.exit(0);
});