import scala.io.StdIn._
object Main extends App {
  val h = readLong

  def solve(n: Long): Long = n match {
    case 0 => 0
    case 1 => 1
    case n => 2 * solve(n / 2) + 1
  }

  println(solve(h))
}
