N = int(input()) def play(): global count global current_location if current_location == N: print(current_location) else: for n in range(current_location, 10**5): move = bin(current_location).count('1') if current_location + move == N: count += 1 print(count) break elif current_location + move < N: current_location += move map.append(n) count += 1 elif current_location + move > N: current_location -= move if current_location in map: print(-1) break else: map.append(n) count += 1 switch() break def switch(): play() current_location = 1 count = 1 map = [] play()