program main

  implicit none

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

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

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

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

  print*, num


end program main
