fun main(args: Array<String>) {
    val h = readLine()!!.toLong()
    var h1 = h
    var cnt = 0
    while (h1 > 1) {
        cnt++
        h1 /= 2
    }
    var ans = 1L
    repeat(cnt) {
        ans += Math.pow(2.0, (it + 1).toDouble()).toLong()
    }
    println(ans)
}
