class Yukicoder: def __init__(self): self.n = int(input()) def run(self): visited = set([]) queue = [1] cnt = 0 while len(queue) != 0: cnt += 1 new_queue = [] for q in queue: if q == self.n: return cnt step = bin(q).count('1') front = q + step back = q - step if front <= self.n and front not in visited: visited.add(front) new_queue.append(front) if 0 < back and back not in visited: visited.add(back) new_queue.append(back) queue = new_queue return -1 y = Yukicoder() print(y.run())