import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    var h = in.readLine().toLong

    var count = 0
    while (h > 0) {
      h >>= 1
      count += 1
    }

    h = 1

    for {
      i <- 1 to count
    } {
      h <<= 1
    }

    System.out.println(h - 1)
  }
}
