program main
    implicit none
    integer(8)::h, at_num, at_all
    read*,h
    at_num = 1
    at_all = 0
    do while(h > 1)
        at_all = at_all + at_num
        h = h / 2
        at_num = at_num * 2
    end do
    at_all = at_all + at_num

    print*, at_all

end program main