import scala.collection.mutable

object Main extends App {
  val  cache = mutable.HashMap.empty[Long, Long]
  def count(hp: Long): Long = if (hp <= 1) 1 else cache.getOrElseUpdate(hp, 1 + 2 * count(hp/2))
  val h = io.StdIn.readLong()
  println(count(h))
}
