object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val h = sc.nextLong
  
  def div2(num: Long, cnt: Long = 0): Long = {
    val div = num / 2
    if (div == 0) cnt
    if (div == 1) cnt + 1
    else div2(div, cnt + 1)
  }
  val divCnt = div2(h)
  val armyCnt = math.pow(2, divCnt).toLong

  def stream(x: Long): Stream[Long] = x #:: stream(x * 2)
  val attackCnt = stream(1).take(divCnt.toInt).sum
  
  println(armyCnt + attackCnt)
}