fun main(args: Array<String>) {
    val h = readLine()?.toLong() ?: return
    val cache = hashMapOf<Long, Long>()
    fun count(h: Long): Long {
        if(h == 1L){
            return 1L
        }
        cache[h]?.let{
            return it
        }
        val c = count(h/2) * 2 + 1
        cache[h] = c
        return c
    }
    println(count(h))
}