program main
  implicit none
  integer(8) :: h, monsters, res
  read (*, *) h
  monsters = 1
  res = 0
  do
    res = res + monsters
    if (h == 1) exit
    h = h / 2
    monsters = monsters * 2
  end do
  write (*, "(i0)") res
end program main
