var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  var line = lines[0]
  var atk_cnt = 0
  var judge = true
  var output = 0
  while (judge) {
    if (line == 1) {
      output = 1
      judge = false
      break
    }
    line = Math.floor(line / 2)
    if (atk_cnt == 0) {
      // 1回目
      output += 1
    } else if (atk_cnt == 1){
      // 2回目
      output += 2
      atk_cnt = 2
    } else {
      // 3回目以降
      atk_cnt = atk_cnt * 2
      output += atk_cnt
    }
    
    if (line == 1) {
      judge = false
      if (output == 1) {
        // 1回目
        output = 3
      } else if (output == 3){
        // 2回目
        output = 3
      } else {
        // 3回目以降
        atk_cnt = atk_cnt * 2
        output += atk_cnt
      }
    } else if (line == 0) {
      output = 1
    }
  }
  console.log(output)
});