fun main(args: Array<String>) {
    abc153d()
}

fun abc153d() {
    val h = readLine()!!.toLong()

    var mons = 1L
    var hp = h
    var answer = 0L
    while (true) {
        answer += mons
        if (hp == 1L) break
        mons *= 2
        hp /= 2
    }

    println(answer)
}
