n = gets.to_i sum = 1 i = 1 count = 1 while sum < n i = sum j = 1 while i >= j sum += 1 if j & i > 0 j *= 2 end i += 1 count += 1 flug = true if sum == n end if flug puts count else puts -1 end