import java.util.*

public fun pow(a : Long, t : Long) : Long {
    if (t == 0L) return 1L
    var x = pow(a, t shr 1)
    x *= x
    if (t and 1L == 1L) x *= a
    return x
}

fun main(args: Array<String>) {
    var x = readLine()!!.toLong()
    var count = 0L
    while(x>1L){
        x /= 2L
        count++
    }
    println(pow(2L, count.toLong()+1)-1)
}
