import java.util.*

fun main(args: Array<String>) {
    var scan = Scanner(System.`in`)
    var a=scan.nextLong()
    var count : Long =1
    var ans : Long =0

    while(a>0)
    {
        ans+=count
        a/=2
        count*=2
    }

    print(ans)
}
