program ABC153D
    implicit none
    integer(8)::H,result,i
    read(5,*)H
    result=0
    i=0
    do
        H=H/2
        result=result+2**i
        if(H<=0)then
            exit
        end if
        i=i+1
    end do

    print'(i0)',result
end program ABC153D