import java.util.*

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