goal = int(input()) # goal_1bit_num = bin(goal) # print(goal_1bit_num.count('1')) stepped = set() answers = set() def step(position, count): if position in stepped: return else: stepped.add(position) if position not in range(1, goal + 1): return if position == goal: answers.add(count) return position_bin = bin(position) step(position + position_bin.count('1'), count + 1) step(position - position_bin.count('1'), count + 1) step(1, 1) if len(answers) == 0: print('-1') else: print(min(answers))