n = int(input()) def count_1(n): return list((bin(n)))[2:].count("1") class BiSugoroku(): def __init__(self, n): self.n = n st = count_1(n) self.plus = self.n + st self.minus = self.n - st q = [BiSugoroku(1)] visited = [1] step = 0 next_flag = True find = False while next_flag: next_flag = False step += 1 old_q = q[:] q = [] for b in old_q: if b.n == n: next_flag = False find = True break else: if b.plus <= n and not (b.plus in visited): q.append(BiSugoroku(b.plus)) visited.append(b.plus) next_flag = True if 0 < b.minus and not (b.minus in visited): q.append(BiSugoroku(b.minus)) visited.append(b.minus) next_flag = True else: print(step if find else -1)