object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val h = sc.nextLong
  
  def loop(div: Long, attackCnt: Long = 0, loopCnt: Long = 0): (Long, Long) = {
    if (div == 1) (attackCnt, loopCnt)
    else loop(div / 2, attackCnt + math.pow(2, loopCnt).toLong, loopCnt + 1)
  }
  
  val (attackCnt, loopCnt) = loop(h)
  
  println(attackCnt + math.pow(2, loopCnt).toLong)
}