fun main(args: Array<String>) {
    val H = readLine()!!.split(" ").map { it.toLong() }.first()
    fun solve(h: Long): Long{
        if (h == 0L) return 0
        return solve(h/2) * 2 + 1
    }
    println(solve(H))
}
