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

  read(*,*) H
  i=0
  amr=0
  cnt=0
  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