MAX_STEP = 100000 def my_bin(x): return bin(x).count("1") if __name__ == '__main__': A = int(input()) bit_one_list = list(map(my_bin, range(1, A + 1))) din_list = [MAX_STEP] * A din_list[0] = 0 now_step = 0 hohaba = 0 step_count = 0 step_queue = [now_step] while len(step_queue) > 0: now_step = step_queue.pop(0) hohaba = bit_one_list[now_step] step_count = din_list[now_step] if now_step + hohaba + 1 <= A and step_count + 1 < din_list[now_step + hohaba]: step_queue.append(now_step + hohaba) din_list[now_step + hohaba] = step_count + 1 if now_step - hohaba + 1 > 0 and step_count + 1 < din_list[now_step - hohaba]: step_queue.append(now_step - hohaba) din_list[now_step - hohaba] = step_count + 1 if din_list[A - 1] != MAX_STEP: print(din_list[A - 1] + 1) else: print(-1)