
import java.math.BigDecimal
import java.math.BigInteger

fun main(args: Array<String>) {

    var H = BigInteger(readLine()!!.toString())

    if (H == BigInteger.ONE) {
        println(1)
        return
    }

    var n = (Math.log(H.toDouble())/Math.log(2.toDouble()) + 1).toInt()

    var answer = BigInteger(BigDecimal(Math.pow(2.toDouble(),n.toDouble())).toString())

    println(answer.minus(BigInteger.ONE))
}