fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    var h = sc.nextLong()

    var r = 0L
    var p = 1L
    while (true) {
        if (h > 1) {
            r += p
            p *= 2
            h /= 2
        } else {
            r += p
            break
        }
    }
    print(r)
}
