n = int(input()) l = [0 for _ in range(n + 1)] l[1] = 1 q = [1] while len(q) != 0 : c = q.pop(0) if c - c.bit_count() > 0 and l[c - c.bit_count()] == 0 : l[c - c.bit_count()] = l[c] + 1 q.append(c - c.bit_count()) if c + c.bit_count() <= n and l[c + c.bit_count()] == 0 : l[c + c.bit_count()] = l[c] + 1 q.append(c + c.bit_count()) if l[n] != 0 : print(l[n]) exit() print(-1)