program main
      implicit none
      integer(16) :: h
      integer(8) :: k, a, ppow

      read *, h

      if ( h == 1 ) then
         print *, '1'
      else
        k = 0
        do
          h = h/2
          k = k + 1
          if ( h == 1 ) exit
        end do
        a = 2
        call pow(a,k+1,ppow)
        print *, ppow - 1 
      end if

contains
subroutine pow(a, n, ppow)
        implicit none
        integer(8), intent(in) :: a, n
        integer(8), intent(out) :: ppow
        integer(8) :: ntmp, atmp

        ppow = 1
        atmp = a
        ntmp = n
        do while ( ntmp > 0 )
          if ( iand(ntmp,1) > 0 ) then
            ppow = ppow * atmp
          end if
          atmp = atmp * atmp
          ntmp = ishft( ntmp, -1 )
        end do

end subroutine pow

end program main
