program D

  implicit none
  integer(8) H
  integer(8) Monsters
  integer i
  integer sum
  read *, H
  sum = 0
  Monsters = 1
  do i = 1, 40
    H = H / 2
    ! print *, Monsters,H
    if ( H == 0 ) then
      ! print *, i
      Monsters = i
      exit
    end if
    Monsters = Monsters + 2**i
  end do
  print '(i0)', 2 **Monsters -1

end program
