def count_one_of_binary(k): binary = bin(k)[2:] n_one = 0 for b in binary: if b == "1": n_one += 1 return n_one def calc_move_amount(current, goal, move): moved = current + move if moved <= goal: return moved else: return current - move def main(): current = 1 N = int(input()) reached = [] time = 1 while True: if current == N: print(time) return one_of_binary = count_one_of_binary(current) current = calc_move_amount(current, N, one_of_binary) if current in reached: print(-1) return reached.append(current) time += 1 main()