from collections import deque def count_1(n): return list((bin(n)))[2:].count("1") class BiSugoroku(): def __init__(self, n, step): self.n = n st = count_1(n) self.plus = self.n + st self.minus = self.n - st self.step = step n = int(input()) q = deque([BiSugoroku(1, 1)]) visited = [1] step = -1 while len(q) > 0: b = q.popleft() if b.n == n: step = b.step break else: if b.plus <= n and not (b.plus in visited): q.append(BiSugoroku(b.plus, b.step + 1)) visited.append(b.plus) if 0 < b.minus and not (b.minus in visited): q.append(BiSugoroku(b.minus, b.step + 1)) visited.append(b.minus) print(step)