program caracal
implicit none
integer(8) :: h,n
n = 0
read(*,*)h
do while(h .ge. 0)
    if (h == 1) then
        write(*,*)2**(n+1)-1
        exit
    else 
        h = h/2
        n = n + 1
    end if
end do


end program caracal