var answer : Long=0
tailrec fun divider(get:Long) {
    var newget= get
    answer+=1
    if(newget == 1L){
        return
    }
    else{
        if(newget % 2L == 1L)  newget-= 1L
        divider(newget/2)
    }
}
fun kakeru(get:Long): Long {
    var retunnumber :Long=1
    for (i in 0 until get ){
        retunnumber *= 2
    }
    return retunnumber
}
fun main(args: Array<String>) {
    val HP: Long? = readLine()?.toLong()
    if (HP != null) {
        divider(HP)
    }
    var num : Long=0
    for (i in 0 until answer){
        num+= kakeru(i)
    }
    println(num)
}