program BegD
  implicit none
  integer(8) :: H, cnt
  integer(8) ::i                                                                              

  read(*,*) H
  i=0
  cnt=0
  if (H.eq.1) then
     print *, "1"
     stop
  endif
  do
     i=i+1
     H=H/2
     cnt=cnt+2**(i-1)
     if(H.eq.1) goto 500
  enddo
500 continue

  print*, cnt+2**i


end program BegD
