object Main {
  def main(args: Array[String]): Unit = {
    var monster_hp = io.StdIn.readLong()
    var divide_num = 0
    var attack_num = 0.toLong

    while( monster_hp > 0 ) {
      divide_num += 1
      monster_hp /= 2.toLong
    }

    ( 0 until divide_num ).foreach { i =>
      attack_num += Math.pow( 2, i ).toLong
    }

    println( attack_num )
  }
}