import scala.io.StdIn.readLine

object Main extends App {
  val h = readLine().toLong
  val log2 = (x: Double) => Math.log10(x) / Math.log10(2.0)
  val sqrt = log2(h).toLong + 1
  println(Math.pow(2, sqrt).toLong - 1)
}