fun main(args: Array<String>) {
    var H = nextLong()
    var A = mutableListOf<Long>()
    var b = 1L
    while (H > 0) {
        A.add(b)
        b = b shl 1
        H /= 2
    }
    println(A.sum())
}
fun next() = readLine()!!
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")