import java.util.Scanner
import java.io.PrintWriter

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val pw = new PrintWriter(System.out)

    var h: Long = sc.nextLong()
    var ans: Long = 0
    var add: Long = 1;
    while (h > 0) {
      ans += add;
      h /= 2;
      add *= 2;
    }
    pw.println(ans)

    pw.flush()
  }
}