import java.util.*

// 入力取得
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

fun main(args: Array<String>) {
    val H = nextLong()
    var h = H
    var n:Long = 0L
    while(h > 0L) {
        h /= 2L
        n++
    }
    n--
    println("${2*powerN(2, n.toInt()) - 1}")
}

fun powerN(number: Long, power: Int): Long {
    var power = power
    if (power == 0) return 1
    var result = number

    while (power > 1) {
        result *= number
        power--
    }

    return result.toLong()
}

inline fun <T> Iterable<T>.sumByLong(selector: (T) -> Long): Long {
    var sum = 0L
    for (element in this) {
        sum += selector(element)
    }
    return sum
}