program main
  implicit none
  integer*8 :: n, cnt = 0
  read *, n

  cnt = cnt + n - 1
  do 
    if (mod(n, 2) /= 0) exit
    n = n / 2
    cnt = cnt + n - 1
  end do
  print '(i0)', cnt - 1
end program
