fun main(arr:Array<String>) {
    val h = readLine()!!.toLong()
    println(getAns(h))
}

fun getAns(hp:Long):Long {
    if(hp == 1L) {
        return 1
    } else {
        val ret = getAns(hp/2)
        return ret * 2 + 1
    }
}