import java.util.*

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

    println(abc153d(h))
}

private fun abc153d(h: Long): Long {
  if (h == 1L) return 1L

  var tmp = h
  var count = 0L
  while (tmp != 1L) {
    tmp /= 2L
    count++
  }

  var ans = 1L
  for (i in 1..count) {
    ans = ans * 2L + 1
  }

  return ans
}
