fun main(args: Array<String>) {
    var H = nextLong()
    var b = 1L
    var ans = 0L
    while (H > 0) {
        ans += b
        b *= 2
        H /= 2
    }
    println(ans)
}
fun next() = readLine()!!
fun nextLong() = next().toLong()
