program main

  implicit none

  integer(8)    :: h, i, n, num
  
  read(*,*) h

  if( h == 1 ) then
    print*, "0"
    stop
  end if

  if ( mod(h,2) == 0 ) then
    n = 0   
    do 
      h = int( h / 2, kind=8 )
      n = n + 1
      if( h < 2 ) exit
    end do
  else
    n = 0   
    do 
      h = int( h / 2, kind=8 )
      if( h < 2 ) exit
      n = n + 1
    end do
  endif

  num = 1
  do i = 1, n
    num = num + 2**i
  end do

  print*, num


end program main
