fun main(args : Array<String>) {
    var h = readLine()!!.toLong()

    var cnt = 0
    while(h > 1) {
        h /= 2
        cnt++
    }

    var ans = 0L
    for (i in 0..cnt) {
        ans += Math.pow(2.0, i.toDouble()).toLong()
    }

    println(ans)
}