object Main extends App{
  import scala.io.StdIn.readLong
  
  val h = readLong
  
  def attack(x:Long):BigInt ={
    def attackRe(acc:BigInt,amount:BigInt,x:Long):BigInt =
    x match{
      case 1 => acc
      case _ => attackRe(acc + amount ,2*amount ,x/2)
    }
    attackRe(1,x)
  }
  
  println(attack(h).toString)
}
