      module modu
        implicit none
        
        contains
        
        recursive function solve( h ) result( r )
          implicit none
          integer(16) :: h,r
          
          if( h==1 )then
            r = 1
          else
            r = 1 + 2*solve( h/2 )
          end if
        end function
      end module
      
      PROGRAM piyo
      use modu
      IMPLICIT NONE
      integer(16) :: h
      
      read*,h
      
      print*,solve( h )
      
      
      
      END PROGRAM