import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    var H = input.nextLong()
    var attackCount = 0L
    
    while (H > 0) {
      attackCount = (attackCount shl 1) or 1
      H = (H shr 1)
    }
    
    println(attackCount)
  }
}