import sys sys.setrecursionlimit(10**6) n = int(input()) point_list = [-1 for _ in range(n+1)] point_list[1] = 1 def move(point): left = point - point.bit_count() right = point + point.bit_count() if right < n + 1: if point_list[right] == -1: point_list[right] = point_list[point] + 1 move(right) if left > 0: if point_list[left] == -1: point_list[left] = point_list[point] + 1 move(left) move(1) if point_list[n] != -1 : print(point_list[n]) else : print(-1)