// https://atcoder.jp/contests/abc153/tasks/abc153_d
import java.lang.Math.*
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val H = scn.nextDouble()

    var a = 1.0
    var sum = 0.0
    var cnt = 1
    while(H>=a){
        sum += a
        a *= 2
        cnt++
    }

    println(String.format("%.0f",sum))
}